From b4c45e8c610c8dc60483b49936dee8a4d0b9c532 Mon Sep 17 00:00:00 2001 From: fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> Date: Fri, 20 May 2022 09:18:27 +0200 Subject: [PATCH] fix: exiting picker from insert mode (#1202) --- lua/telescope/actions/init.lua | 5 ++++- lua/telescope/actions/set.lua | 2 +- lua/telescope/pickers.lua | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 11b46a2..d448e79 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -343,14 +343,17 @@ end --- Close the Telescope window, usually used within an action ---@param prompt_bufnr number: The prompt bufnr actions.close = function(prompt_bufnr) - action_state.get_current_history():reset() local picker = action_state.get_current_picker(prompt_bufnr) local original_win_id = picker.original_win_id + local original_cursor = a.nvim_win_get_cursor(original_win_id) actions.close_pum(prompt_bufnr) require("telescope.pickers").on_close_prompt(prompt_bufnr) pcall(a.nvim_set_current_win, original_win_id) + if a.nvim_get_mode().mode == "i" then + pcall(a.nvim_win_set_cursor, original_win_id, { original_cursor[1], original_cursor[2] + 1 }) + end end --- Close the Telescope window, usually used within an action
diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index 4faf947..3164f72 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -131,7 +131,7 @@ action_set.edit = function(prompt_bufnr, command) local entry_bufnr = entry.bufnr local picker = action_state.get_current_picker(prompt_bufnr) - require("telescope.actions").close(prompt_bufnr) + require("telescope.pickers").on_close_prompt(prompt_bufnr) local win_id = picker.get_selection_window(picker, entry) if picker.push_cursor_on_edit then diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index e7c4c7c..c4aa6fc 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -1416,6 +1416,7 @@ end function pickers.on_close_prompt(prompt_bufnr) local status = state.get_status(prompt_bufnr) local picker = status.picker + require("telescope.actions.state").get_current_history():reset() if type(picker.cache_picker) == "table" then local cached_pickers = state.get_global_key "cached_pickers" or {}