Skip to content

Commit

Permalink
store cursor-position in snippetString to more accurately restore it.
Browse files Browse the repository at this point in the history
Cache `static_text` (for insertNodes) and don't query it anew while
luasnip is operating. This is valid under the assumption that all
changes to the buffer are due to luasnip while an api-function (jump,
expand, etc.) is running.

This is enabled by session.luasnip_changedtick
which is set as soon as an api-function is called, and prevents
re-fetching snippetStrings from the buffer (which in turn allows us to
set the cursor-position once, and then have it propagate through all
updates that are triggered subsequently).

This commit also replaces no_region_check_wrap with api_do, which is
more general (handles both jump_active, which prevents recursive
api-calls and luasnip_changedtick)
  • Loading branch information
L3MON4D3 committed Nov 13, 2024
1 parent f78bf74 commit a938528
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 107 deletions.
9 changes: 7 additions & 2 deletions lua/luasnip/extras/select_choice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ local session = require("luasnip.session")
local ls = require("luasnip")
local node_util = require("luasnip.nodes.util")

-- in this procedure, make sure that api_leave is called before
-- set_choice_callback exits.
local function set_choice_callback(data)
return function(_, indx)
if not indx then
ls._api_leave()
return
end
-- feed+immediately execute i to enter INSERT after vim.ui.input closes.
-- vim.api.nvim_feedkeys("i", "x", false)
ls.set_choice(indx, {cursor_restore_data = data})
ls._set_choice(indx, {cursor_restore_data = data})
ls._api_leave()
end
end

Expand All @@ -20,7 +24,8 @@ local function select_choice()
)
local active = session.current_nodes[vim.api.nvim_get_current_buf()]

local restore_data = node_util.store_cursor_node_relative(active)
ls._api_enter()
local restore_data = node_util.store_cursor_node_relative(active, {place_cursor_mark = false})
vim.ui.select(
ls.get_current_choices(),
{ kind = "luasnip" },
Expand Down
Loading

0 comments on commit a938528

Please sign in to comment.