fix: fix keep insert when going from telescope window to telescope window (#1600)

Also fixes `initial_mode`

Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
This commit is contained in:
kylo252
2022-04-22 16:13:32 +02:00
committed by GitHub
parent 5a58b1f535
commit cc1a3440f9
5 changed files with 33 additions and 40 deletions

View File

@@ -343,28 +343,26 @@ end
--- Close the Telescope window, usually used within an action
---@param prompt_bufnr number: The prompt bufnr
actions.close = function(prompt_bufnr)
actions._close(prompt_bufnr, false)
end
--- Close the Telescope window and specify if you want to keep insert mode or not
---@param prompt_bufnr number: The prompt bufnr
---@param keepinsert boolean: Remain in INSERT mode if true
actions._close = function(prompt_bufnr, keepinsert)
action_state.get_current_history():reset()
local picker = action_state.get_current_picker(prompt_bufnr)
local prompt_win = state.get_status(prompt_bufnr).prompt_win
local original_win_id = picker.original_win_id
actions.close_pum(prompt_bufnr)
if not keepinsert then
vim.cmd [[stopinsert]]
end
vim.api.nvim_win_close(prompt_win, true)
pcall(vim.cmd, string.format([[silent bdelete! %s]], prompt_bufnr))
pcall(a.nvim_set_current_win, original_win_id)
end
--- Close the Telescope window, usually used within an action<br>
--- Deprecated and no longer needed, does the same as |telescope.actions.close|. Might be removed in the future
---@deprecated
---@param prompt_bufnr number: The prompt bufnr
actions._close = function(prompt_bufnr)
actions.close(prompt_bufnr)
end
local set_edit_line = function(prompt_bufnr, fname, prefix, postfix)
postfix = vim.F.if_nil(postfix, "")
local selection = action_state.get_selected_entry()
@@ -460,7 +458,7 @@ end
---@param prompt_bufnr number: The prompt bufnr
actions.insert_symbol_i = function(prompt_bufnr)
local symbol = action_state.get_selected_entry().value[1]
actions._close(prompt_bufnr, true)
actions.close(prompt_bufnr)
vim.schedule(function()
vim.cmd [[startinsert]]
vim.api.nvim_put({ symbol }, "", true, true)