mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
vim-patch:8.1.0245: calling setline() in TextChangedI autocmd breaks undo
Problem: Calling setline() in TextChangedI autocmd breaks undo. (Jason
Felice)
Solution: Don't save lines for undo when already saved. (closes vim/vim#3291)
91d2e783b4
This commit is contained in:
@@ -1392,11 +1392,20 @@ ins_redraw (
|
|||||||
&& !pum_visible()) {
|
&& !pum_visible()) {
|
||||||
aco_save_T aco;
|
aco_save_T aco;
|
||||||
|
|
||||||
|
// Sync undo when the autocommand calls setline() or append(), so that
|
||||||
|
// it can be undone separately.
|
||||||
|
u_sync_once = 2;
|
||||||
|
|
||||||
// save and restore curwin and curbuf, in case the autocmd changes them
|
// save and restore curwin and curbuf, in case the autocmd changes them
|
||||||
aucmd_prepbuf(&aco, curbuf);
|
aucmd_prepbuf(&aco, curbuf);
|
||||||
apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, false, curbuf);
|
||||||
aucmd_restbuf(&aco);
|
aucmd_restbuf(&aco);
|
||||||
curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
|
curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
|
||||||
|
|
||||||
|
if (u_sync_once == 1) {
|
||||||
|
ins_need_undo = true;
|
||||||
|
}
|
||||||
|
u_sync_once = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger TextChangedP if changedtick differs. When the popupmenu closes
|
// Trigger TextChangedP if changedtick differs. When the popupmenu closes
|
||||||
|
@@ -567,7 +567,7 @@ func Test_OptionSet()
|
|||||||
" Cleanup
|
" Cleanup
|
||||||
au! OptionSet
|
au! OptionSet
|
||||||
for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']
|
for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']
|
||||||
exe printf(":set %s&vi", opt)
|
exe printf(":set %s&vim", opt)
|
||||||
endfor
|
endfor
|
||||||
call test_override('starting', 0)
|
call test_override('starting', 0)
|
||||||
delfunc! AutoCommandOptionSet
|
delfunc! AutoCommandOptionSet
|
||||||
@@ -1221,3 +1221,29 @@ func Test_ChangedP()
|
|||||||
|
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
let g:setline_handled = v:false
|
||||||
|
func! SetLineOne()
|
||||||
|
if !g:setline_handled
|
||||||
|
call setline(1, "(x)")
|
||||||
|
let g:setline_handled = v:true
|
||||||
|
endif
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_TextChangedI_with_setline()
|
||||||
|
throw 'skipped: Nvim does not support test_override()'
|
||||||
|
new
|
||||||
|
call test_override('char_avail', 1)
|
||||||
|
autocmd TextChangedI <buffer> call SetLineOne()
|
||||||
|
call feedkeys("i(\<CR>\<Esc>", 'tx')
|
||||||
|
call assert_equal('(', getline(1))
|
||||||
|
call assert_equal('x)', getline(2))
|
||||||
|
undo
|
||||||
|
call assert_equal('(', getline(1))
|
||||||
|
call assert_equal('', getline(2))
|
||||||
|
undo
|
||||||
|
call assert_equal('', getline(1))
|
||||||
|
|
||||||
|
call test_override('starting', 0)
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
Reference in New Issue
Block a user