aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-12 09:50:17 +0800
committerGitHub <noreply@github.com>2023-08-12 09:50:17 +0800
commit58a1ef8e6a93c615379f6fbe7234697bcdc42b3e (patch)
treec15b5ac2889ceacf923cca47b2954ab291c9dadf /test
parent6c07a189f2d10a533af8a51819ea96c45e0c567e (diff)
downloadrneovim-58a1ef8e6a93c615379f6fbe7234697bcdc42b3e.tar.gz
rneovim-58a1ef8e6a93c615379f6fbe7234697bcdc42b3e.tar.bz2
rneovim-58a1ef8e6a93c615379f6fbe7234697bcdc42b3e.zip
fix(events): avoid unnecessary CursorMoved (#24675)
Problem: Temporarily changing current window in a script causes CursorMoved to be triggerd. Solution: Don't trigger CursorMoved if neither curwin nor cursor changed between two checks.
Diffstat (limited to 'test')
-rw-r--r--test/functional/autocmd/cursormoved_spec.lua39
1 files changed, 25 insertions, 14 deletions
diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua
index 64b63c3205..854e14b088 100644
--- a/test/functional/autocmd/cursormoved_spec.lua
+++ b/test/functional/autocmd/cursormoved_spec.lua
@@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
-local funcs = helpers.funcs
+local meths = helpers.meths
local source = helpers.source
local command = helpers.command
@@ -12,10 +12,10 @@ describe('CursorMoved', function()
it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
source([[
- call setline(1, 'foo')
- let g:log = []
- autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
- autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
+ call setline(1, 'foo')
+ let g:log = []
+ autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
+ autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
]])
eq({}, eval('g:log'))
command('new')
@@ -24,23 +24,34 @@ describe('CursorMoved', function()
eq({'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1'}, eval('g:log'))
end)
+ it('is not triggered by temporarily switching window', function()
+ source([[
+ let g:cursormoved = 0
+ vnew
+ autocmd CursorMoved * let g:cursormoved += 1
+ ]])
+ command('wincmd w | wincmd p')
+ eq(0, eval('g:cursormoved'))
+ end)
+
it("is not triggered by functions that don't change the window", function()
source([[
- let g:cursormoved = 0
- let g:buf = bufnr('%')
- vsplit foo
- autocmd CursorMoved * let g:cursormoved += 1
- call nvim_buf_set_lines(g:buf, 0, -1, v:true, ['aaa'])
+ let g:cursormoved = 0
+ let g:buf = bufnr('%')
+ vsplit foo
+ autocmd CursorMoved * let g:cursormoved += 1
]])
- eq({'aaa'}, funcs.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
+ meths.buf_set_lines(eval('g:buf'), 0, -1, true, {'aaa'})
+ eq(0, eval('g:cursormoved'))
+ eq({'aaa'}, meths.buf_get_lines(eval('g:buf'), 0, -1, true))
eq(0, eval('g:cursormoved'))
end)
it("is not triggered by cursor movement prior to first CursorMoved instantiation", function()
source([[
- let g:cursormoved = 0
- autocmd! CursorMoved
- autocmd CursorMoved * let g:cursormoved += 1
+ let g:cursormoved = 0
+ autocmd! CursorMoved
+ autocmd CursorMoved * let g:cursormoved += 1
]])
eq(0, eval('g:cursormoved'))
end)