Skip to content

Commit bcbef84

Browse files
committed
make jump_into_func responsible for adjusting the currently active node.
This might break some previously-working jump_into_funcs.
1 parent a1a60eb commit bcbef84

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lua/luasnip/init.lua

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@ local function locally_jumpable(dir)
185185
end
186186

187187
local function _jump_into_default(snippet)
188+
local current_buf = vim.api.nvim_get_current_buf()
189+
if session.current_nodes[current_buf] then
190+
local current_node = session.current_nodes[current_buf]
191+
if current_node.pos > 0 then
192+
-- snippet is nested, notify current insertNode about expansion.
193+
current_node.inner_active = true
194+
else
195+
-- snippet was expanded behind a previously active one, leave the i(0)
196+
-- properly (and remove the snippet on error).
197+
local ok, err = pcall(current_node.input_leave, current_node)
198+
if not ok then
199+
log.warn("Error while leaving snippet: ", err)
200+
current_node.parent.snippet:remove_from_jumplist()
201+
end
202+
end
203+
end
204+
188205
return util.no_region_check_wrap(snippet.jump_into, snippet, 1)
189206
end
190207

@@ -238,24 +255,6 @@ local function snip_expand(snippet, opts)
238255
opts.jumplist_insert_func
239256
)
240257

241-
local current_buf = vim.api.nvim_get_current_buf()
242-
243-
if session.current_nodes[current_buf] then
244-
local current_node = session.current_nodes[current_buf]
245-
if current_node.pos > 0 then
246-
-- snippet is nested, notify current insertNode about expansion.
247-
current_node.inner_active = true
248-
else
249-
-- snippet was expanded behind a previously active one, leave the i(0)
250-
-- properly (and remove the snippet on error).
251-
local ok, err = pcall(current_node.input_leave, current_node)
252-
if not ok then
253-
log.warn("Error while leaving snippet: ", err)
254-
current_node.parent.snippet:remove_from_jumplist()
255-
end
256-
end
257-
end
258-
259258
-- jump_into-callback returns new active node.
260259
session.current_nodes[vim.api.nvim_get_current_buf()] =
261260
opts.jump_into_func(snip)

0 commit comments

Comments
 (0)