mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
fix(snippet): early return for final tabstop #35115
The cursor movement autocommand can not detect when the final tabstop $0 is directly adjacent to another tabstop, which prevents ending the snippet session. The fix is an early return when jumping.
This commit is contained in:
@@ -585,6 +585,12 @@ function M.jump(direction)
|
|||||||
M._session.current_tabstop = dest
|
M._session.current_tabstop = dest
|
||||||
select_tabstop(dest)
|
select_tabstop(dest)
|
||||||
|
|
||||||
|
-- The cursor is not on a tabstop so exit the session.
|
||||||
|
if dest.index == 0 then
|
||||||
|
M.stop()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Activate expansion of the destination tabstop.
|
-- Activate expansion of the destination tabstop.
|
||||||
M._session:set_group_gravity(dest.index, false)
|
M._session:set_group_gravity(dest.index, false)
|
||||||
|
|
||||||
|
@@ -214,6 +214,20 @@ describe('vim.snippet', function()
|
|||||||
eq(false, exec_lua('return vim.snippet.active()'))
|
eq(false, exec_lua('return vim.snippet.active()'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('stop session when jumping to $0', function()
|
||||||
|
test_expand_success({ 'local ${1:name} = ${2:value}$0' }, { 'local name = value' })
|
||||||
|
-- Jump to $2
|
||||||
|
feed('<Tab>')
|
||||||
|
poke_eventloop()
|
||||||
|
-- Jump to $0 (stop snippet)
|
||||||
|
feed('<Tab>')
|
||||||
|
poke_eventloop()
|
||||||
|
-- Insert literal \t
|
||||||
|
feed('<Tab>')
|
||||||
|
poke_eventloop()
|
||||||
|
eq({ 'local name = value\t' }, buf_lines(0))
|
||||||
|
end)
|
||||||
|
|
||||||
it('inserts choice', function()
|
it('inserts choice', function()
|
||||||
test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
|
test_expand_success({ 'console.${1|assert,log,error|}()' }, { 'console.()' })
|
||||||
wait_for_pum()
|
wait_for_pum()
|
||||||
|
@@ -1309,7 +1309,7 @@ describe('vim.lsp.completion: integration', function()
|
|||||||
end)
|
end)
|
||||||
feed('<C-n><C-y>')
|
feed('<C-n><C-y>')
|
||||||
eq(
|
eq(
|
||||||
{ true, { 'if true then', '\t', 'end' } },
|
{ false, { 'if true then', '\t', 'end' } },
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
return {
|
return {
|
||||||
vim.snippet.active({ direction = 1 }),
|
vim.snippet.active({ direction = 1 }),
|
||||||
|
Reference in New Issue
Block a user