1
0
forked from aniani/vim

patch 8.1.1681: insert stray "{" when listener gets buffer line

Problem:    Insert stray "{" when listener gets buffer line. (Paul Jolly)
Solution:   Flush the cached line after invoking listeners. (closes #4455)
This commit is contained in:
Bram Moolenaar
2019-07-13 20:14:45 +02:00
parent 63d0dad874
commit 0fb286e82d
3 changed files with 31 additions and 1 deletions

View File

@@ -2836,8 +2836,10 @@ ml_append_int(
#ifdef FEAT_EVAL
// When inserting above recorded changes: flush the changes before changing
// the text.
// the text. Then flush the cached line, it may become invalid.
may_invoke_listeners(buf, lnum + 1, lnum + 1, 1);
if (curbuf->b_ml.ml_line_lnum != 0)
ml_flush_line(curbuf);
#endif
#ifdef FEAT_TEXT_PROP

View File

@@ -242,3 +242,29 @@ func Test_listener_garbage_collect()
delfunc MyListener
bwipe!
endfunc
" This verifies the fix for issue #4455
func Test_listener_caches_buffer_line()
new
inoremap <silent> <CR> <CR><Esc>O
function EchoChanges(bufnr, start, end, added, changes)
for l:change in a:changes
let text = getbufline(a:bufnr, l:change.lnum, l:change.end-1+l:change.added)
endfor
endfunction
let lid = listener_add("EchoChanges")
set autoindent
set cindent
call setline(1, ["{", "\tif true {}", "}"])
exe "normal /{}\nl"
call feedkeys("i\r\e", 'xt')
call assert_equal(["{", "\tif true {", "", "\t}", "}"], getline(1, 5))
bwipe!
delfunc EchoChanges
call listener_remove(lid)
iunmap <CR>
set nocindent
endfunc

View File

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