fix(snippet): cancel session on <Esc> in Select mode #39238

Problem: <Esc> in a Select-mode tabstop leaves the session and highlight active.
CursorMoved isn’t triggered since the cursor doesn’t move.

Solution: use ModeChanged (s:n) instead. Defer with vim.schedule() to avoid transient
s:n from jump().
This commit is contained in:
glepnir
2026-05-10 21:19:12 +08:00
committed by GitHub
parent 5d1910e1e0
commit 2dc0efccb0
3 changed files with 50 additions and 0 deletions

View File

@@ -269,6 +269,18 @@ describe('vim.snippet', function()
eq(false, exec_lua('return vim.snippet.active()'))
end)
it('cancels session on <Esc> from tabstop #39220', function()
local ns = api.nvim_create_namespace('nvim.snippet')
test_expand_success({ 'local ${1:name} = ${2:value}' }, { 'local name = value' })
eq('s', fn.mode())
eq(true, exec_lua('return vim.snippet.active()'))
t.neq(0, #api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
feed('<Esc>')
poke_eventloop()
eq(false, exec_lua('return vim.snippet.active()'))
eq(0, #api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
end)
it('stop session when jumping to $0', function()
test_expand_success({ 'local ${1:name} = ${2:value}$0' }, { 'local name = value' })
-- Jump to $2