summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers.lua
diff options
context:
space:
mode:
authorkylo252 <59826753+kylo252@users.noreply.github.com>2022-04-22 16:13:32 +0200
committerGitHub <noreply@github.com>2022-04-22 16:13:32 +0200
commitcc1a3440f9ba6f28a8ca0bfff867f60c2d80c353 (patch)
tree965bd4cb118219c3f45dfdd7442379938f849938 /lua/telescope/pickers.lua
parent5a58b1f53577a8e124d703b5f8f3a29d07416753 (diff)
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>
Diffstat (limited to 'lua/telescope/pickers.lua')
-rw-r--r--lua/telescope/pickers.lua38
1 files changed, 16 insertions, 22 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 4555ffb..97e5ec6 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -432,21 +432,19 @@ function Picker:find()
pcall(a.nvim_buf_set_option, prompt_bufnr, "filetype", "TelescopePrompt")
pcall(a.nvim_buf_set_option, results_bufnr, "filetype", "TelescopeResults")
- -- TODO(async): I wonder if this should actually happen _before_ we nvim_buf_attach.
- -- This way the buffer would always start with what we think it should when we start the loop.
- if self.initial_mode == "insert" or self.initial_mode == "normal" then
- -- required for set_prompt to work adequately
- vim.cmd [[startinsert!]]
- if self.default_text then
- self:set_prompt(self.default_text)
- end
- if self.initial_mode == "normal" then
- -- otherwise (i) insert mode exitted faster than `picker:set_prompt`; (ii) cursor on wrong pos
- await_schedule(function()
- vim.cmd [[stopinsert]]
- end)
- end
- else
+ if self.default_text then
+ self:set_prompt(self.default_text)
+ end
+
+ if self.initial_mode == "insert" then
+ vim.schedule(function()
+ -- startinsert! did not reliable do `A` no idea why, i even looked at the source code
+ -- Example: live_grep -> type something -> quit -> Telescope pickers -> resume -> cursor of by one
+ if vim.fn.mode() ~= "i" then
+ vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<ESC>A", true, false, true), "n", true)
+ end
+ end)
+ elseif self.initial_mode ~= "normal" then
error("Invalid setting for initial_mode: " .. self.initial_mode)
end
@@ -722,10 +720,8 @@ function Picker:delete_selection(delete_cb)
end, 50)
end
-function Picker:set_prompt(str)
- -- TODO(conni2461): As soon as prompt_buffers are fix use this:
- -- vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, 1, false, { str })
- vim.api.nvim_feedkeys(str, "n", false)
+function Picker:set_prompt(text)
+ self:reset_prompt(text)
end
--- Closes the windows for the prompt, results and preview
@@ -890,7 +886,6 @@ end
function Picker:reset_prompt(text)
local prompt_text = self.prompt_prefix .. (text or "")
vim.api.nvim_buf_set_lines(self.prompt_bufnr, 0, -1, false, { prompt_text })
-
self:_reset_prefix_color(self._current_prefix_hl_group)
if text then
@@ -1223,7 +1218,7 @@ end
--- Close all open Telescope pickers
function Picker:close_existing_pickers()
for _, prompt_bufnr in ipairs(state.get_existing_prompts()) do
- pcall(actions._close, prompt_bufnr, true)
+ pcall(actions.close, prompt_bufnr)
end
end
@@ -1529,7 +1524,6 @@ function Picker:_resume_picker()
self.cache_picker.is_cached = false
-- if text changed, required to set anew to restart finder; otherwise hl and selection
if self.cache_picker.cached_prompt ~= self.default_text then
- self:reset_prompt()
self:set_prompt(self.default_text)
else
-- scheduling required to apply highlighting and selection appropriately