patch 9.0.2075: TextChangedI may not always trigger

Commit: 
https://github.com/vim/vim/commit/4bca4897a12dfb91b3b27e3083fd5f370bd857d1
Author: Christian Brabandt <[email protected]>
Date:   Fri Oct 27 19:26:49 2023 +0200

    patch 9.0.2075: TextChangedI may not always trigger
    
    Problem:  TextChangedI may not always trigger
    Solution: trigger it in more cases: for insert/
              append/change operations, and when
              opening a new line,
    
    fixes: #13367
    closes: #13375
    
    Signed-off-by: Christian Brabandt <[email protected]>
    Signed-off-by: Evgeni Chasnovski <[email protected]>

diff --git a/src/edit.c b/src/edit.c
index 014d1c7ed..51753f68b 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -174,9 +174,6 @@ edit(
        return FALSE;
     }
     ins_compl_clear();     // clear stuff for CTRL-X mode
-    // Reset Changedtick_i, so that TextChangedI will only be triggered for 
stuff
-    // from insert mode
-    curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
 
     /*
      * Trigger InsertEnter autocommands.  Do not do this for "r<CR>" or "grx".
diff --git a/src/normal.c b/src/normal.c
index 9f203b858..a06d61e6f 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -6292,6 +6292,8 @@ n_opencmd(cmdarg_T *cap)
        (void)hasFolding(curwin->w_cursor.lnum,
                NULL, &curwin->w_cursor.lnum);
 #endif
+    // trigger TextChangedI for the 'o/O' command
+    curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
     if (u_save((linenr_T)(curwin->w_cursor.lnum -
                    (cap->cmdchar == 'O' ? 1 : 0)),
                (linenr_T)(curwin->w_cursor.lnum +
@@ -7083,6 +7085,10 @@ invoke_edit(
     // Always reset "restart_edit", this is not a restarted edit.
     restart_edit = 0;
 
+    // Reset Changedtick_i, so that TextChangedI will only be triggered for 
stuff
+    // from insert mode, for 'o/O' this has already been done in n_opencmd
+    if (cap->cmdchar != 'O' && cap->cmdchar != 'o')
+       curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
     if (edit(cmd, startln, cap->count1))
        cap->retval |= CA_COMMAND_BUSY;
 
diff --git a/src/ops.c b/src/ops.c
index aa6f4af37..c0a2981d6 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -4134,6 +4134,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int 
gui_yank)
                // before.
                restore_lbr(lbr_saved);
 #endif
+               // trigger TextChangedI
+               curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
+
                if (op_change(oap))     // will call edit()
                    cap->retval |= CA_COMMAND_BUSY;
                if (restart_edit == 0)
@@ -4244,6 +4247,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int 
gui_yank)
                // before.
                restore_lbr(lbr_saved);
 #endif
+               // trigger TextChangedI
+               curbuf->b_last_changedtick_i = CHANGEDTICK(curbuf);
+
                op_insert(oap, cap->count1);
 #ifdef FEAT_LINEBREAK
                // Reset linebreak, so that formatting works correctly.
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 1e1bb4540..0652a6fb6 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -2566,28 +2566,27 @@ func Test_ChangedP()
   call cursor(3, 1)
   let g:autocmd = ''
   call feedkeys("o\<esc>", 'tnix')
-  " `TextChangedI` triggers only if text is actually changed in Insert mode
-  call assert_equal('', g:autocmd)
+  call assert_equal('I', g:autocmd)
 
   let g:autocmd = ''
   call feedkeys("Sf", 'tnix')
-  call assert_equal('I', g:autocmd)
+  call assert_equal('II', g:autocmd)
 
   let g:autocmd = ''
   call feedkeys("Sf\<C-N>", 'tnix')
-  call assert_equal('IP', g:autocmd)
+  call assert_equal('IIP', g:autocmd)
 
   let g:autocmd = ''
   call feedkeys("Sf\<C-N>\<C-N>", 'tnix')
-  call assert_equal('IPP', g:autocmd)
+  call assert_equal('IIPP', g:autocmd)
 
   let g:autocmd = ''
   call feedkeys("Sf\<C-N>\<C-N>\<C-N>", 'tnix')
-  call assert_equal('IPPP', g:autocmd)
+  call assert_equal('IIPPP', g:autocmd)
 
   let g:autocmd = ''
   call feedkeys("Sf\<C-N>\<C-N>\<C-N>\<C-N>", 'tnix')
-  call assert_equal('IPPPP', g:autocmd)
+  call assert_equal('IIPPPP', g:autocmd)
 
   call assert_equal(['foo', 'bar', 'foobar', 'foo'], getline(1, '$'))
   " TODO: how should it handle completeopt=noinsert,noselect?
@@ -3621,6 +3620,25 @@ func Test_Changed_ChangedI()
   call feedkeys("ibar\<esc>", 'tnix')
   call assert_equal('', g:autocmd_n)
 
+  " If change is a mix of Normal and Insert modes, TextChangedI should trigger
+  func s:validate_mixed_textchangedi(keys)
+    call feedkeys("ifoo\<esc>", 'tnix')
+    let g:autocmd_i = ''
+    let g:autocmd_n = ''
+    call feedkeys(a:keys, 'tnix')
+    call assert_notequal('', g:autocmd_i)
+    call assert_equal('', g:autocmd_n)
+  endfunc
+
+  call s:validate_mixed_textchangedi("o\<esc>")
+  call s:validate_mixed_textchangedi("O\<esc>")
+  call s:validate_mixed_textchangedi("ciw\<esc>")
+  call s:validate_mixed_textchangedi("cc\<esc>")
+  call s:validate_mixed_textchangedi("C\<esc>")
+  call s:validate_mixed_textchangedi("s\<esc>")
+  call s:validate_mixed_textchangedi("S\<esc>")
+
+
   " CleanUp
   call test_override("char_avail", 0)
   au! TextChanged  <buffer>
diff --git a/src/version.c b/src/version.c
index 55465a214..8c9085720 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2075,
 /**/
     2074,
 /**/

-- 
-- 
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/E1qwQtM-008Bjb-6Q%40256bit.org.

Raspunde prin e-mail lui