2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2019-03-28 18:08:57 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local eval = n.eval
|
|
|
|
local api = n.api
|
|
|
|
local source = n.source
|
|
|
|
local command = n.command
|
2019-03-28 18:08:57 -07:00
|
|
|
|
|
|
|
describe('CursorMoved', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
2023-06-03 18:09:22 -07:00
|
|
|
it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
|
2019-03-28 18:08:57 -07:00
|
|
|
source([[
|
2023-08-11 18:50:17 -07:00
|
|
|
call setline(1, 'foo')
|
|
|
|
let g:log = []
|
|
|
|
autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
|
|
|
|
autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
|
2019-03-28 18:08:57 -07:00
|
|
|
]])
|
2023-06-03 18:09:22 -07:00
|
|
|
eq({}, eval('g:log'))
|
|
|
|
command('new')
|
|
|
|
eq({ 'BufEnter2', 'CursorMoved2' }, eval('g:log'))
|
|
|
|
command('wincmd w')
|
|
|
|
eq({ 'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1' }, eval('g:log'))
|
2019-03-28 18:08:57 -07:00
|
|
|
end)
|
|
|
|
|
2023-08-11 18:50:17 -07:00
|
|
|
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)
|
|
|
|
|
2019-03-28 18:08:57 -07:00
|
|
|
it("is not triggered by functions that don't change the window", function()
|
|
|
|
source([[
|
2023-08-11 18:50:17 -07:00
|
|
|
let g:cursormoved = 0
|
|
|
|
let g:buf = bufnr('%')
|
|
|
|
vsplit foo
|
|
|
|
autocmd CursorMoved * let g:cursormoved += 1
|
2019-03-28 18:08:57 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' })
|
2023-08-11 18:50:17 -07:00
|
|
|
eq(0, eval('g:cursormoved'))
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
|
2019-03-28 18:08:57 -07:00
|
|
|
eq(0, eval('g:cursormoved'))
|
|
|
|
end)
|
2021-12-18 20:18:47 -07:00
|
|
|
|
|
|
|
it('is not triggered by cursor movement prior to first CursorMoved instantiation', function()
|
|
|
|
source([[
|
2023-08-11 18:50:17 -07:00
|
|
|
let g:cursormoved = 0
|
|
|
|
autocmd! CursorMoved
|
|
|
|
autocmd CursorMoved * let g:cursormoved += 1
|
2021-12-18 20:18:47 -07:00
|
|
|
]])
|
|
|
|
eq(0, eval('g:cursormoved'))
|
|
|
|
end)
|
2019-03-28 18:08:57 -07:00
|
|
|
end)
|