From b188b7750c78c0dbe0c61d79d824673a53ff82db Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Wed, 7 Sep 2022 07:40:02 -0700 Subject: [PATCH] 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. --- lua/dressing/select/init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/dressing/select/init.lua b/lua/dressing/select/init.lua index 9a77a1f..4320b49 100644 --- a/lua/dressing/select/init.lua +++ b/lua/dressing/select/init.lua @@ -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)