Patch 8.2.3517
Problem:    TextChanged does not trigger after TextChangedI.
Solution:   Store the tick separately for TextChangedI. (Christian Brabandt,
            closes #8968, closes #8932)
Files:      src/buffer.c, src/bufwrite.c, src/edit.c, src/structs.h,
            src/testdir/test_autocmd.vim


*** ../vim-8.2.3516/src/buffer.c        2021-10-09 15:39:20.459884353 +0100
--- src/buffer.c        2021-10-16 09:23:19.957161103 +0100
***************
*** 327,332 ****
--- 327,333 ----
      // Set last_changedtick to avoid triggering a TextChanged autocommand 
right
      // after it was added.
      curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
+     curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
      curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf);
  
      // require "!" to overwrite the file, because it wasn't read completely
*** ../vim-8.2.3516/src/bufwrite.c      2021-10-14 21:27:50.642253782 +0100
--- src/bufwrite.c      2021-10-16 09:26:54.895558071 +0100
***************
*** 2422,2429 ****
            && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL))
      {
        unchanged(buf, TRUE, FALSE);
!       // b:changedtick is may be incremented in unchanged() but that
!       // should not trigger a TextChanged event.
        if (buf->b_last_changedtick + 1 == CHANGEDTICK(buf))
            buf->b_last_changedtick = CHANGEDTICK(buf);
        u_unchanged(buf);
--- 2422,2429 ----
            && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL))
      {
        unchanged(buf, TRUE, FALSE);
!       // b:changedtick may be incremented in unchanged() but that should not
!       // trigger a TextChanged event.
        if (buf->b_last_changedtick + 1 == CHANGEDTICK(buf))
            buf->b_last_changedtick = CHANGEDTICK(buf);
        u_unchanged(buf);
*** ../vim-8.2.3516/src/edit.c  2021-10-03 16:22:01.963285362 +0100
--- src/edit.c  2021-10-16 09:27:18.815835675 +0100
***************
*** 1477,1485 ****
        last_cursormoved = curwin->w_cursor;
      }
  
!     // Trigger TextChangedI if b_changedtick differs.
      if (ready && has_textchangedI()
!           && curbuf->b_last_changedtick != CHANGEDTICK(curbuf)
            && !pum_visible())
      {
        aco_save_T      aco;
--- 1477,1485 ----
        last_cursormoved = curwin->w_cursor;
      }
  
!     // Trigger TextChangedI if b_changedtick_i differs.
      if (ready && has_textchangedI()
!           && curbuf->b_last_changedtick_i != CHANGEDTICK(curbuf)
            && !pum_visible())
      {
        aco_save_T      aco;
***************
*** 1489,1503 ****
        aucmd_prepbuf(&aco, curbuf);
        apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf);
        aucmd_restbuf(&aco);
!       curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
        if (tick != CHANGEDTICK(curbuf))  // see ins_apply_autocmds()
            u_save(curwin->w_cursor.lnum,
                                        (linenr_T)(curwin->w_cursor.lnum + 1));
      }
  
!     // Trigger TextChangedP if b_changedtick differs. When the popupmenu 
closes
!     // TextChangedI will need to trigger for backwards compatibility, thus use
!     // different b_last_changedtick* variables.
      if (ready && has_textchangedP()
            && curbuf->b_last_changedtick_pum != CHANGEDTICK(curbuf)
            && pum_visible())
--- 1489,1503 ----
        aucmd_prepbuf(&aco, curbuf);
        apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf);
        aucmd_restbuf(&aco);
!       curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
        if (tick != CHANGEDTICK(curbuf))  // see ins_apply_autocmds()
            u_save(curwin->w_cursor.lnum,
                                        (linenr_T)(curwin->w_cursor.lnum + 1));
      }
  
!     // Trigger TextChangedP if b_changedtick_pum differs. When the popupmenu
!     // closes TextChangedI will need to trigger for backwards compatibility,
!     // thus use different b_last_changedtick* variables.
      if (ready && has_textchangedP()
            && curbuf->b_last_changedtick_pum != CHANGEDTICK(curbuf)
            && pum_visible())
*** ../vim-8.2.3516/src/structs.h       2021-10-14 21:27:50.646253845 +0100
--- src/structs.h       2021-10-16 09:28:54.408962438 +0100
***************
*** 2701,2710 ****
                                // incremented for each change, also for undo
  #define CHANGEDTICK(buf) ((buf)->b_ct_di.di_tv.vval.v_number)
  
!     varnumber_T       b_last_changedtick; // b:changedtick when TextChanged or
!                                   // TextChangedI was last triggered.
!     varnumber_T       b_last_changedtick_pum; // b:changedtick when 
TextChangedP was
                                        // last triggered.
  
      int               b_saving;       // Set to TRUE if we are in the middle 
of
                                // saving the buffer.
--- 2701,2710 ----
                                // incremented for each change, also for undo
  #define CHANGEDTICK(buf) ((buf)->b_ct_di.di_tv.vval.v_number)
  
!     varnumber_T       b_last_changedtick;     // b:changedtick when 
TextChanged was
                                        // last triggered.
+     varnumber_T       b_last_changedtick_pum; // b:changedtick for 
TextChangedP
+     varnumber_T       b_last_changedtick_i;   // b:changedtick for 
TextChangedI
  
      int               b_saving;       // Set to TRUE if we are in the middle 
of
                                // saving the buffer.
*** ../vim-8.2.3516/src/testdir/test_autocmd.vim        2021-10-03 
16:22:01.963285362 +0100
--- src/testdir/test_autocmd.vim        2021-10-16 11:55:19.826395366 +0100
***************
*** 1929,1934 ****
--- 1929,1935 ----
      let g:autocmd .= a:char
    endfunc
  
+   " TextChanged will not be triggered, only check that it isn't.
    au! TextChanged <buffer> :call TextChangedAutocmd('N')
    au! TextChangedI <buffer> :call TextChangedAutocmd('I')
    au! TextChangedP <buffer> :call TextChangedAutocmd('P')
***************
*** 2863,2867 ****
--- 2864,2905 ----
    augroup END
  endfunc
  
+ " Test TextChangedI and TextChanged
+ func Test_Changed_ChangedI()
+   new
+   call test_override("char_avail", 1)
+   let [g:autocmd_i, g:autocmd_n] = ['','']
+ 
+   func! TextChangedAutocmdI(char)
+     let g:autocmd_{tolower(a:char)} = a:char .. b:changedtick
+   endfunc
+ 
+   augroup Test_TextChanged
+     au!
+     au TextChanged  <buffer> :call TextChangedAutocmdI('N')
+     au TextChangedI <buffer> :call TextChangedAutocmdI('I')
+   augroup END
+ 
+   call feedkeys("ifoo\<esc>", 'tnix')
+   " TODO: Test test does not seem to trigger TextChanged autocommand, this
+   " requires running Vim in a terminal window.
+   " call assert_equal('N3', g:autocmd_n)
+   call assert_equal('I3', g:autocmd_i)
+ 
+   call feedkeys("yyp", 'tnix')
+   " TODO: Test test does not seem to trigger TextChanged autocommand.
+   " call assert_equal('N4', g:autocmd_n)
+   call assert_equal('I3', g:autocmd_i)
+ 
+   " CleanUp
+   call test_override("char_avail", 0)
+   au! TextChanged  <buffer>
+   au! TextChangedI <buffer>
+   augroup! Test_TextChanged
+   delfu TextChangedAutocmdI
+   unlet! g:autocmd_i g:autocmd_n
+ 
+   bw!
+ endfunc
  
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.3516/src/version.c       2021-10-15 22:25:37.785385044 +0100
--- src/version.c       2021-10-16 09:26:28.179250275 +0100
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3517,
  /**/

-- 
"Hit any key to continue" does _not_ mean you can hit the on/off button!

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211016105944.6C893C80053%40moolenaar.net.

Raspunde prin e-mail lui