aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-01-03 20:08:13 -0500
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-01-03 20:15:32 -0500
commit4c4bcecc4a1b817be742856ac8600c90d24c42f4 (patch)
tree626535512615676a18ae253fc4d8e238945dd60e
parent234232ff4e4b0885485de1054cd5c09897015d6a (diff)
downloadrneovim-4c4bcecc4a1b817be742856ac8600c90d24c42f4.tar.gz
rneovim-4c4bcecc4a1b817be742856ac8600c90d24c42f4.tar.bz2
rneovim-4c4bcecc4a1b817be742856ac8600c90d24c42f4.zip
vim-patch:8.0.1817: a timer may change v:count unexpectedly
Problem: A timer may change v:count unexpectedly. Solution: Save and restore v:count and similar variables when a timer callback is invoked. (closes vim/vim#2897) https://github.com/vim/vim/commit/b0f42ba60d9e6d101d103421ba0c351811615c15
-rw-r--r--src/nvim/testdir/test_timers.vim32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim
index bd63d94729..cadec88af9 100644
--- a/src/nvim/testdir/test_timers.vim
+++ b/src/nvim/testdir/test_timers.vim
@@ -5,6 +5,7 @@ if !has('timers')
endif
source shared.vim
+source screendump.vim
source load.vim
func MyHandler(timer)
@@ -263,4 +264,35 @@ func Test_ex_mode()
call timer_stop(timer)
endfunc
+func Test_restore_count()
+ if !CanRunVimInTerminal()
+ return
+ endif
+ " Check that v:count is saved and restored, not changed by a timer.
+ call writefile([
+ \ 'nnoremap <expr><silent> L v:count ? v:count . "l" : "l"',
+ \ 'func Doit(id)',
+ \ ' normal 3j',
+ \ 'endfunc',
+ \ 'call timer_start(100, "Doit")',
+ \ ], 'Xtrcscript')
+ call writefile([
+ \ '1-1234',
+ \ '2-1234',
+ \ '3-1234',
+ \ ], 'Xtrctext')
+ let buf = RunVimInTerminal('-S Xtrcscript Xtrctext', {})
+
+ " Wait for the timer to move the cursor to the third line.
+ call WaitForAssert({-> assert_equal(3, term_getcursor(buf)[0])})
+ call assert_equal(1, term_getcursor(buf)[1])
+ " Now check that v:count has not been set to 3
+ call term_sendkeys(buf, 'L')
+ call WaitForAssert({-> assert_equal(2, term_getcursor(buf)[1])})
+
+ call StopVimInTerminal(buf)
+ call delete('Xtrcscript')
+ call delete('Xtrctext')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab