Mercurial > vim
changeset 19044:af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Commit: https://github.com/vim/vim/commit/f10997a1543eb0724d882da3678bacd44e647141
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 3 21:00:02 2020 +0100
patch 8.2.0082: when reusing a buffer listeners are not cleared
Problem: When reusing a buffer listeners are not cleared. (Axel Forsman)
Solution: Clear listeners when reusing a buffer. (closes https://github.com/vim/vim/issues/5431)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 03 Jan 2020 21:00:16 +0100 |
parents | 9c3bd0bafcdc |
children | 143d44d8f477 |
files | src/buffer.c src/testdir/test_listener.vim src/version.c |
diffstat | 3 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/buffer.c +++ b/src/buffer.c @@ -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
--- a/src/testdir/test_listener.vim +++ b/src/testdir/test_listener.vim @@ -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