aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-15 01:13:38 -0400
committerJan Edmund Lazo <janedmundlazo@hotmail.com>2018-08-15 01:27:30 -0400
commita0938e068f99b56a3474fd739f1a3f52240d28f7 (patch)
tree0198c25725af8eb172da5d9340ad3d83cae7e00a
parentee37a0c79ae61931b15570ed1877779dc7bd0dad (diff)
downloadrneovim-a0938e068f99b56a3474fd739f1a3f52240d28f7.tar.gz
rneovim-a0938e068f99b56a3474fd739f1a3f52240d28f7.tar.bz2
rneovim-a0938e068f99b56a3474fd739f1a3f52240d28f7.zip
vim-patch:8.0.1633: a TextChanged autocmd triggers when it is defined
Problem: A TextChanged autocmd triggers when it is defined after creating a buffer. Solution: Set b_last_changedtick when opening a buffer. (Hirohito Highlight, closes vim/vim#2742) https://github.com/vim/vim/commit/8c64a36e40b8746404f7151abe6849393396af10
-rw-r--r--src/nvim/buffer.c5
-rw-r--r--src/nvim/testdir/test_autocmd.vim21
2 files changed, 26 insertions, 0 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 3fadcc75bf..00d472b4c8 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -296,6 +296,11 @@ open_buffer (
}
save_file_ff(curbuf); // keep this fileformat
+ // Set last_changedtick to avoid triggering a TextChanged autocommand right
+ // after it was added.
+ curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
+ curbuf->b_last_changedtick_pum = buf_get_changedtick(curbuf);
+
/* require "!" to overwrite the file, because it wasn't read completely */
if (aborting())
curbuf->b_flags |= BF_READERR;
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index 7173558d50..b1502eff89 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -1,5 +1,7 @@
" Tests for autocommands
+source shared.vim
+
func! s:cleanup_buffers() abort
for bnr in range(1, bufnr('$'))
if bufloaded(bnr) && bufnr('%') != bnr
@@ -1269,3 +1271,22 @@ func Test_TextChangedI_with_setline()
call test_override('starting', 0)
bwipe!
endfunc
+
+func Test_Changed_FirstTime()
+ if !has('terminal') || has('gui_running')
+ return
+ endif
+ " Prepare file for TextChanged event.
+ call writefile([''], 'Xchanged.txt')
+ let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3})
+ call assert_equal('running', term_getstatus(buf))
+ " It's only adding autocmd, so that no event occurs.
+ call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>")
+ call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>")
+ call WaitFor({-> term_getstatus(buf) == 'finished'})
+ call assert_equal([''], readfile('Xchanged.txt'))
+
+ " clean up
+ call delete('Xchanged.txt')
+ bwipe!
+endfunc