diff options
| author | fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> | 2022-05-04 15:00:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-04 15:00:28 +0200 |
| commit | c93276acd34f5cb20d7cc2de15a8f40526433660 (patch) | |
| tree | 7f77526ee589d5579f27b8de1d43a7b247a4546e /lua/telescope/pickers.lua | |
| parent | 80e4313cc893c1df8a20c5760237afefc875afa2 (diff) | |
fix: initial mode setting issues (#1917)
Diffstat (limited to 'lua/telescope/pickers.lua')
| -rw-r--r-- | lua/telescope/pickers.lua | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 77f88f3..1d20df1 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -423,6 +423,28 @@ function Picker:find() local find_id = self:_next_find_id() + if self.default_text then + self:set_prompt(self.default_text) + end + + if vim.tbl_contains({ "insert", "normal" }, self.initial_mode) then + local mode = vim.fn.mode() + local keys + if self.initial_mode == "normal" then + -- n: A<ESC> makes sure cursor is at always at end of prompt w/o default_text + keys = mode ~= "n" and "<ESC>A<ESC>" or "A<ESC>" + else + -- always fully retrigger insert mode: required for going from one picker to next + keys = mode ~= "n" and "<ESC>A" or "A" + end + a.nvim_feedkeys(a.nvim_replace_termcodes(keys, true, false, true), "n", true) + else + utils.notify( + "pickers.find", + { msg = "`initial_mode` should be one of ['normal', 'insert'] but passed " .. self.initial_mode, level = "ERROR" } + ) + end + local main_loop = async.void(function() self.sorter:_init() @@ -430,23 +452,6 @@ function Picker:find() pcall(a.nvim_buf_set_option, prompt_bufnr, "filetype", "TelescopePrompt") pcall(a.nvim_buf_set_option, results_bufnr, "filetype", "TelescopeResults") - 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 - local mode = vim.fn.mode() - if mode ~= "i" then - a.nvim_input(mode ~= "n" and "<ESC>A" or "A") - end - end) - elseif self.initial_mode ~= "normal" then - error("Invalid setting for initial_mode: " .. self.initial_mode) - end - await_schedule() while true do |
