fix(snippet): cancel session on ESC in insert-mode #41555

Problem:
If a snippet does not have a placeholder, we use insert mode instead of
select mode. From here <Esc> leaves the session and highlight active.

Solution:
Cancel the session on <Esc>.
This commit is contained in:
Nathan Zeng
2026-08-30 05:32:55 -07:00
committed by GitHub
parent 5e0b1464b2
commit 39862231b2
2 changed files with 11 additions and 1 deletions

View File

@@ -480,7 +480,7 @@ local function setup_autocmds(bufnr)
desc = 'Stop the snippet session when leaving select mode',
buf = bufnr,
}, function(args)
if args.match ~= 's:n' then
if args.match ~= 's:n' and args.match ~= 'i:n' then
return
end
vim.schedule(function()

View File

@@ -280,6 +280,16 @@ describe('vim.snippet', function()
poke_eventloop()
eq(false, exec_lua('return vim.snippet.active()'))
eq(0, #api.nvim_buf_get_extmarks(0, ns, 0, -1, {}))
feed('dal')
test_expand_success({ 'local $1 = ${2:value}' }, { 'local = value' })
eq('i', 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()