summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-07-13 20:14:45 +0200
committerBram Moolenaar <Bram@vim.org>2019-07-13 20:14:45 +0200
commit0fb286e82d28730fcb3293894dd4df2e069eaf9a (patch)
treea8110a1004c03a2a2a20ce52d1da86d271a815d6
parent63d0dad874e6f949c18dd2b3c8c14d59cad58062 (diff)
patch 8.1.1681: insert stray "{" when listener gets buffer linev8.1.1681
Problem: Insert stray "{" when listener gets buffer line. (Paul Jolly) Solution: Flush the cached line after invoking listeners. (closes #4455)
-rw-r--r--src/memline.c4
-rw-r--r--src/testdir/test_listener.vim26
-rw-r--r--src/version.c2
3 files changed, 31 insertions, 1 deletions
diff --git a/src/memline.c b/src/memline.c
index 0e3bdb8b6b..b9de06e1df 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -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
diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim
index ed501c2ef8..6a68ae64b5 100644
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index eaa8047cd0..fff8d22a23 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1681,
+/**/
1680,
/**/
1679,