From ac353e87aecf02315d82a3ad22725d2bc8140f0c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 28 Oct 2023 10:42:18 +0800 Subject: vim-patch:9.0.2075: TextChangedI may not always trigger (#25808) Problem: TextChangedI may not always trigger Solution: trigger it in more cases: for insert/ append/change operations, and when opening a new line, fixes: vim/vim#13367 closes: vim/vim#13375 https://github.com/vim/vim/commit/4bca4897a12dfb91b3b27e3083fd5f370bd857d1 Co-authored-by: Christian Brabandt --- test/functional/autocmd/textchanged_spec.lua | 39 +++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'test/functional/autocmd/textchanged_spec.lua') diff --git a/test/functional/autocmd/textchanged_spec.lua b/test/functional/autocmd/textchanged_spec.lua index b90a0fd020..b621eb36bf 100644 --- a/test/functional/autocmd/textchanged_spec.lua +++ b/test/functional/autocmd/textchanged_spec.lua @@ -4,6 +4,7 @@ local exec = helpers.exec local command = helpers.command local feed = helpers.feed local eq = helpers.eq +local neq = helpers.neq local eval = helpers.eval local poke_eventloop = helpers.poke_eventloop @@ -26,14 +27,14 @@ it('TextChangedI and TextChangedP autocommands', function() poke_eventloop() feed('') -- TextChangedI triggers only if text is actually changed in Insert mode - eq('', eval('g:autocmd')) + eq('I', eval('g:autocmd')) command([[let g:autocmd = '']]) feed('S') poke_eventloop() feed('f') poke_eventloop() - eq('I', eval('g:autocmd')) + eq('II', eval('g:autocmd')) feed('') command([[let g:autocmd = '']]) @@ -43,7 +44,7 @@ it('TextChangedI and TextChangedP autocommands', function() poke_eventloop() feed('') poke_eventloop() - eq('IP', eval('g:autocmd')) + eq('IIP', eval('g:autocmd')) feed('') command([[let g:autocmd = '']]) @@ -55,7 +56,7 @@ it('TextChangedI and TextChangedP autocommands', function() poke_eventloop() feed('') poke_eventloop() - eq('IPP', eval('g:autocmd')) + eq('IIPP', eval('g:autocmd')) feed('') command([[let g:autocmd = '']]) @@ -69,7 +70,7 @@ it('TextChangedI and TextChangedP autocommands', function() poke_eventloop() feed('') poke_eventloop() - eq('IPPP', eval('g:autocmd')) + eq('IIPPP', eval('g:autocmd')) feed('') command([[let g:autocmd = '']]) @@ -84,7 +85,7 @@ it('TextChangedI and TextChangedP autocommands', function() feed('') poke_eventloop() feed('') - eq('IPPPP', eval('g:autocmd')) + eq('IIPPPP', eval('g:autocmd')) feed('') eq({'foo', 'bar', 'foobar', 'foo'}, eval('getline(1, "$")')) @@ -145,17 +146,37 @@ it('TextChangedI and TextChanged', function() eq('', eval('g:autocmd_n')) eq('I5', eval('g:autocmd_i')) - command([[call feedkeys("yyp", 'tnix')]]) + feed('yyp') eq('N6', eval('g:autocmd_n')) eq('I5', eval('g:autocmd_i')) -- TextChangedI should only trigger if change was done in Insert mode command([[let g:autocmd_i = '']]) - command([[call feedkeys("yypi\", 'tnix')]]) + feed('yypi') eq('', eval('g:autocmd_i')) -- TextChanged should only trigger if change was done in Normal mode command([[let g:autocmd_n = '']]) - command([[call feedkeys("ibar\", 'tnix')]]) + feed('ibar') eq('', eval('g:autocmd_n')) + + local function validate_mixed_textchangedi(keys) + feed('ifoo') + command([[let g:autocmd_i = '']]) + command([[let g:autocmd_n = '']]) + for _, s in ipairs(keys) do + feed(s) + poke_eventloop() + end + neq('', eval('g:autocmd_i')) + eq('', eval('g:autocmd_n')) + end + + validate_mixed_textchangedi({'o', ''}) + validate_mixed_textchangedi({'O', ''}) + validate_mixed_textchangedi({'ciw', ''}) + validate_mixed_textchangedi({'cc', ''}) + validate_mixed_textchangedi({'C', ''}) + validate_mixed_textchangedi({'s', ''}) + validate_mixed_textchangedi({'S', ''}) end) -- cgit