vim-patch:9.1.0088: TextChanged not triggered for :norm! commands (#27405)

Problem:  TextChanged not triggered for :norm! commands
          (machakann, after v9.0.2031)
Solution: Only reset curbuf->b_last_changedtick if TextChangedI
          was triggered in insert mode (and not blocked)

Note: for unknown reasons, the test fails on Windows (but seems to work
fine when running interactively)

fixes: vim/vim#13967
closes: vim/vim#13984

c9e79e5284

Cherry-pick test_autocmd.vim change from patch 8.2.4149.

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2024-02-10 06:53:26 +08:00 committed by GitHub
parent 0d4d3e4325
commit 3f419d84fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -363,7 +363,13 @@ static void insert_enter(InsertState *s)
ins_apply_autocmds(EVENT_INSERTLEAVE);
}
did_cursorhold = false;
curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
// ins_redraw() triggers TextChangedI only when no characters
// are in the typeahead buffer, so only reset curbuf->b_last_changedtick
// if the TextChangedI was not blocked by char_avail() (e.g. using :norm!)
if (!char_avail()) {
curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
}
}
static int insert_check(VimState *state)

View File

@ -180,3 +180,14 @@ it('TextChangedI and TextChanged', function()
validate_mixed_textchangedi({ 's', '<esc>' })
validate_mixed_textchangedi({ 'S', '<esc>' })
end)
-- oldtest: Test_TextChanged_with_norm()
it('TextChanged is triggered after :norm that enters Insert mode', function()
exec([[
let g:a = 0
au TextChanged * let g:a += 1
]])
eq(0, eval('g:a'))
feed(':norm! ia<CR>')
eq(1, eval('g:a'))
end)

View File

@ -2533,7 +2533,25 @@ func Test_TextChangedI_with_setline()
call assert_equal('', getline(1))
call assert_equal('', getline(2))
call test_override('starting', 0)
call test_override('char_avail', 0)
bwipe!
endfunc
func Test_TextChanged_with_norm()
" For unknown reason this fails on MS-Windows
CheckNotMSWindows
CheckFeature terminal
let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
call assert_equal('running', term_getstatus(buf))
call term_sendkeys(buf, ":let g:a=0\<cr>")
call term_wait(buf, 50)
call term_sendkeys(buf, ":au! TextChanged * :let g:a+=1\<cr>")
call term_wait(buf, 50)
call term_sendkeys(buf, ":norm! ia\<cr>")
call term_wait(buf, 50)
call term_sendkeys(buf, ":echo g:a\<cr>")
call term_wait(buf, 50)
call WaitForAssert({-> assert_match('^1.*$', term_getline(buf, 3))})
bwipe!
endfunc