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

4bca4897a1

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2023-10-28 10:42:18 +08:00
committed by GitHub
parent f97248db75
commit ac353e87ae
5 changed files with 75 additions and 26 deletions

View File

@@ -2476,28 +2476,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)
let g:autocmd = ''
call feedkeys("Sf", 'tnix')
call assert_equal('I', g:autocmd)
let g:autocmd = ''
call feedkeys("Sf", 'tnix')
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?
@@ -3489,6 +3488,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>