mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(events): avoid superfluous CursorMovedI on first autocmd (#33588)
This commit is contained in:
@@ -1050,9 +1050,10 @@ int autocmd_register(int64_t id, event_T event, const char *pat, int patlen, int
|
|||||||
get_mode(last_mode);
|
get_mode(last_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the event is CursorMoved, update the last cursor position
|
// If the event is CursorMoved or CursorMovedI, update the last cursor position
|
||||||
// position to avoid immediately triggering the autocommand
|
// position to avoid immediately triggering the autocommand
|
||||||
if (event == EVENT_CURSORMOVED && !has_event(EVENT_CURSORMOVED)) {
|
if ((event == EVENT_CURSORMOVED && !has_event(EVENT_CURSORMOVED))
|
||||||
|
|| (event == EVENT_CURSORMOVEDI && !has_event(EVENT_CURSORMOVEDI))) {
|
||||||
last_cursormoved_win = curwin;
|
last_cursormoved_win = curwin;
|
||||||
last_cursormoved = curwin->w_cursor;
|
last_cursormoved = curwin->w_cursor;
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ local eval = n.eval
|
|||||||
local api = n.api
|
local api = n.api
|
||||||
local source = n.source
|
local source = n.source
|
||||||
local command = n.command
|
local command = n.command
|
||||||
|
local feed = n.feed
|
||||||
|
|
||||||
describe('CursorMoved', function()
|
describe('CursorMoved', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
@@ -49,11 +50,34 @@ describe('CursorMoved', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('is not triggered by cursor movement prior to first CursorMoved instantiation', function()
|
it('is not triggered by cursor movement prior to first CursorMoved instantiation', function()
|
||||||
|
eq({}, api.nvim_get_autocmds({ event = 'CursorMoved' }))
|
||||||
|
feed('ifoobar<Esc>')
|
||||||
source([[
|
source([[
|
||||||
let g:cursormoved = 0
|
let g:cursormoved = 0
|
||||||
autocmd! CursorMoved
|
|
||||||
autocmd CursorMoved * let g:cursormoved += 1
|
autocmd CursorMoved * let g:cursormoved += 1
|
||||||
]])
|
]])
|
||||||
eq(0, eval('g:cursormoved'))
|
eq(0, eval('g:cursormoved'))
|
||||||
|
feed('<Ignore>')
|
||||||
|
eq(0, eval('g:cursormoved'))
|
||||||
|
feed('0')
|
||||||
|
eq(1, eval('g:cursormoved'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('CursorMovedI', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('is not triggered by cursor movement prior to first CursorMovedI instantiation', function()
|
||||||
|
eq({}, api.nvim_get_autocmds({ event = 'CursorMovedI' }))
|
||||||
|
feed('ifoobar')
|
||||||
|
source([[
|
||||||
|
let g:cursormovedi = 0
|
||||||
|
autocmd CursorMovedI * let g:cursormovedi += 1
|
||||||
|
]])
|
||||||
|
eq(0, eval('g:cursormovedi'))
|
||||||
|
feed('<Ignore>')
|
||||||
|
eq(0, eval('g:cursormovedi'))
|
||||||
|
feed('<Home>')
|
||||||
|
eq(1, eval('g:cursormovedi'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user