]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2075: TextChangedI may not always trigger v9.0.2075
authorChristian Brabandt <cb@256bit.org>
Fri, 27 Oct 2023 17:26:49 +0000 (19:26 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 27 Oct 2023 17:26:49 +0000 (19:26 +0200)
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 <cb@256bit.org>
Signed-off-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
src/edit.c
src/normal.c
src/ops.c
src/testdir/test_autocmd.vim
src/version.c

index 014d1c7ed38bdfeae4ec71ca720ea13aff072ebe..51753f68bf673bc5ed1363e830277a84362a477a 100644 (file)
@@ -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".
index 9f203b858768e89fabc2f7e370f01b90819a9627..a06d61e6fce7d16d12646ed0ac040ce06ad0c3a9 100644 (file)
@@ -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;
 
index aa6f4af37a7c9656cf30592830c11d043c20b95d..c0a2981d68770498d25448ac1f48305f5fd61f8f 100644 (file)
--- 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.
index 1e1bb4540a9cfc08e98d0285f5e2a75ca24990c8..0652a6fb67125857b37cafc1b4aa631e6fc10f5b 100644 (file)
@@ -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>
index 55465a2147cbd63415d35bdd3f90905a5ba29e38..8c908572041e56521c5545ff1233a31700e6588c 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2075,
 /**/
     2074,
 /**/