Skip to content

Commit

Permalink
fix: restore cursor position after select
Browse files Browse the repository at this point in the history
Some of the select implementations, due to the fact that they switch
from normal mode to insert mode and back, cause the cursor to move
backwards by one column. This can have unfortunate effects if you are
relying on the cursor position to perform some operation.
  • Loading branch information
stevearc committed Sep 7, 2022
1 parent 9cdb3e0 commit b188b77
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/dressing/select/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,15 @@ return vim.schedule_wrap(function(items, opts, on_choice)
end

local backend, name = get_backend(config)
backend.select(config[name], items, opts, on_choice)
local winid = vim.api.nvim_get_current_win()
local cursor = vim.api.nvim_win_get_cursor(winid)
backend.select(
config[name],
items,
opts,
vim.schedule_wrap(function(...)
vim.api.nvim_win_set_cursor(winid, cursor)
on_choice(...)
end)
)
end)

0 comments on commit b188b77

Please sign in to comment.