]> granicus.if.org Git - vim/commitdiff
patch 8.2.0082: when reusing a buffer listeners are not cleared v8.2.0082
authorBram Moolenaar <Bram@vim.org>
Fri, 3 Jan 2020 20:00:02 +0000 (21:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 3 Jan 2020 20:00:02 +0000 (21:00 +0100)
Problem:    When reusing a buffer listeners are not cleared. (Axel Forsman)
Solution:   Clear listeners when reusing a buffer. (closes #5431)

src/buffer.c
src/testdir/test_listener.vim
src/version.c

index eb6b28772865451c9344ad6e2de4466e341674b2..0a68d484e500b8074b2f4b4140fe197713e3be05 100644 (file)
@@ -979,6 +979,7 @@ free_buffer_stuff(
        hash_init(&buf->b_vars->dv_hashtab);
        init_changedtick(buf);
        CHANGEDTICK(buf) = tick;
+       remove_listeners(buf);
     }
 #endif
     uc_clear(&buf->b_ucmds);           // clear local user commands
index a7815dc046d41c6975a7b813f47e266ef2978bb5..a263abadd2d0b731ba11a42e44a801a8fbb67b1b 100644 (file)
@@ -295,3 +295,34 @@ func Test_listener_undo_line_number()
   delfunc EchoChanges
   call listener_remove(lid)
 endfunc
+
+func Test_listener_cleared_newbuf()
+  func Listener(bufnr, start, end, added, changes)
+    let g:gotCalled += 1
+  endfunc
+  new
+  " check that listening works
+  let g:gotCalled = 0
+  let lid = listener_add("Listener")
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(1, g:gotCalled)
+  %bwipe!
+  let bufnr = bufnr()
+  let b:testing = 123
+  let lid = listener_add("Listener")
+  enew!
+  " check buffer is reused
+  call assert_equal(bufnr, bufnr())
+  call assert_false(exists('b:testing'))
+
+  " check that listening stops when reusing the buffer
+  let g:gotCalled = 0
+  call feedkeys("axxx\<Esc>", 'xt')
+  call listener_flush(bufnr())
+  call assert_equal(0, g:gotCalled)
+  unlet g:gotCalled
+
+  bwipe!
+  delfunc Listener
+endfunc
index cff754f28dc409de7e7689d7b842212d9716ee11..6dd07bb686080a0e95392df863cad12b3b401e25 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    82,
 /**/
     81,
 /**/