patch 9.0.2031: TextChangedI may be triggered by non-insert mode change

Problem:  `TextChangedI` can trigger on entering Insert mode if there
          was previously a change not in Insert mode.
Solution: Make it trigger only when text is actually changed in Insert
          mode.

closes: #13265
closes: #13338

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
This commit is contained in:
Evgeni Chasnovski
2023-10-15 09:59:00 +02:00
committed by Christian Brabandt
parent 47510f3d65
commit d7ae263af8
3 changed files with 23 additions and 6 deletions

View File

@ -174,6 +174,9 @@ 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".
@ -840,6 +843,7 @@ doESCkey:
if (cmdchar != 'r' && cmdchar != 'v' && c != Ctrl_C)
ins_apply_autocmds(EVENT_INSERTLEAVE);
did_cursorhold = FALSE;
curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
return (c == Ctrl_O);
}
continue;

View File

@ -2566,27 +2566,28 @@ func Test_ChangedP()
call cursor(3, 1)
let g:autocmd = ''
call feedkeys("o\<esc>", 'tnix')
call assert_equal('I', g:autocmd)
" `TextChangedI` triggers only if text is actually changed in Insert mode
call assert_equal('', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf", 'tnix')
call assert_equal('II', g:autocmd)
call assert_equal('I', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf\<C-N>", 'tnix')
call assert_equal('IIP', g:autocmd)
call assert_equal('IP', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf\<C-N>\<C-N>", 'tnix')
call assert_equal('IIPP', g:autocmd)
call assert_equal('IPP', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf\<C-N>\<C-N>\<C-N>", 'tnix')
call assert_equal('IIPPP', g:autocmd)
call assert_equal('IPPP', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf\<C-N>\<C-N>\<C-N>\<C-N>", 'tnix')
call assert_equal('IIPPPP', g:autocmd)
call assert_equal('IPPPP', g:autocmd)
call assert_equal(['foo', 'bar', 'foobar', 'foo'], getline(1, '$'))
" TODO: how should it handle completeopt=noinsert,noselect?
@ -3610,6 +3611,16 @@ func Test_Changed_ChangedI()
" call assert_equal('N4', g:autocmd_n)
call assert_equal('I3', g:autocmd_i)
" TextChangedI should only trigger if change was done in Insert mode
let g:autocmd_i = ''
call feedkeys("yypi\<esc>", 'tnix')
call assert_equal('', g:autocmd_i)
" TextChanged should only trigger if change was done in Normal mode
let g:autocmd_n = ''
call feedkeys("ibar\<esc>", 'tnix')
call assert_equal('', g:autocmd_n)
" CleanUp
call test_override("char_avail", 0)
au! TextChanged <buffer>

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2031,
/**/
2030,
/**/