Skip to content

Commit

Permalink
enqueue cursor-movement due to update in typeahead.
Browse files Browse the repository at this point in the history
Otherwise the jump_into from change_choice may complete after the
cursor-movement due to the subsequent update.
  • Loading branch information
L3MON4D3 committed Nov 6, 2024
1 parent 733ccb2 commit 211254b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lua/luasnip/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ local function restore_cursor_pos_relative(node, data)
local selection_to = util.pos_add(node.mark:get_endpoint(1), data.selection_other_end_end_relative)
feedkeys.select_range(selection_from, selection_to)
else
util.set_cursor_0ind(
util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative)
)
feedkeys.move_to(util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative))
end
end

Expand Down
11 changes: 11 additions & 0 deletions lua/luasnip/util/feedkeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ function M.insert_at(pos)
end, id)
end

-- move, without changing mode.
function M.move_to(pos)
local id = next_id()
enqueued_cursor_state = {pos = pos, id = id}

enqueue_action(function()
util.set_cursor_0ind(pos)
M.confirm(id)
end, id)
end

function M.confirm(id)
executing_id = nil

Expand Down
49 changes: 49 additions & 0 deletions tests/integration/session_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2280,4 +2280,53 @@ describe("session", function()
|]],
})
end)

it("position is restored correctly after change_choice.", function()
feed("ifn")
expand()
jump(1)
jump(1)
jump(1)
jump(1)
change(1)
feed("asdf")
change(1)
change(1)
change(1)
-- currently wrong!
screen:expect({
grid = [[
/** |
* A short Description |
*/ |
public void myFunc()^ { {4:●} |
|
} |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |
]]
})
end)
end)

0 comments on commit 211254b

Please sign in to comment.