fix: restore cursor position after select

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.
This commit is contained in:
Steven Arcangeli 2022-09-07 07:40:02 -07:00
parent 9cdb3e0f09
commit b188b7750c
1 changed files with 11 additions and 1 deletions

View File

@ -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)