summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers.lua
diff options
context:
space:
mode:
authorfdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>2022-05-03 08:53:22 +0200
committerGitHub <noreply@github.com>2022-05-03 08:53:22 +0200
commite454a0ad37ba72a14bebe516f99935c16f33ca50 (patch)
tree168a67d79f6f7e4f010d089b62ba109fdc61a792 /lua/telescope/pickers.lua
parent23e28d066a55a8e33bff33196f7bd65ea3ecbdbe (diff)
fix(pickers): misc initial_mode setting fixes (#1895)
Diffstat (limited to 'lua/telescope/pickers.lua')
-rw-r--r--lua/telescope/pickers.lua20
1 files changed, 14 insertions, 6 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 77f88f3..3cf180f 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -434,16 +434,24 @@ function Picker:find()
self:set_prompt(self.default_text)
end
- if self.initial_mode == "insert" then
+ if vim.tbl_contains({ "insert", "normal" }, self.initial_mode) 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")
+ if self.initial_mode == "normal" then
+ if mode ~= "n" then
+ a.nvim_input "<ESC>"
+ end
+ else
+ -- Example: live_grep -> type something -> quit -> Telescope pickers -> resume -> cursor of by one
+ -- vim.cmd doesn't schedule appropriately, bypass with `nvim_input`
+ -- histdel('cmd', -1) to not pollute command history with startinsert & echon to clear "startinsert" msg
+ if mode ~= "i" then
+ local cmd = ":startinsert!|call histdel('cmd', -1)|echon ''<CR>"
+ a.nvim_input(mode ~= "n" and "<ESC>" .. cmd or cmd)
+ end
end
end)
- elseif self.initial_mode ~= "normal" then
+ else
error("Invalid setting for initial_mode: " .. self.initial_mode)
end