Files
neovim/test/functional/autocmd/cursormoved_spec.lua
Michael Lingelbach b42e0c40c8 fix: update last cursor on first CursorMoved (#16698)
Closes https://github.com/neovim/neovim/issues/16625 https://github.com/neovim/neovim/issues/12923

The first defined CursorMoved autocommand will immediately
fire if the cursor has previously moved upon definition
of the autocommand.

Plugins add dummy autocommands such as:

```lua
autocmd CursorMoved * execute ''
```

to avoid this behavior.

Instead, when defining a new CursorHold autocommand, force
update the last cursor position.

See https://github.com/vim/vim/issues/2053
2021-12-18 19:18:47 -08:00

43 lines
1.1 KiB
Lua

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 source = helpers.source
describe('CursorMoved', function()
before_each(clear)
it('is triggered by changing windows', function()
source([[
let g:cursormoved = 0
vsplit
autocmd CursorMoved * let g:cursormoved += 1
wincmd w
wincmd w
]])
eq(2, 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'])
]])
eq({'aaa'}, funcs.nvim_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 * let g:cursormoved += 1
]])
eq(0, eval('g:cursormoved'))
end)
end)