summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers.lua
diff options
context:
space:
mode:
authorfdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>2021-09-01 17:09:26 +0200
committerGitHub <noreply@github.com>2021-09-01 17:09:26 +0200
commit8710baa6fb37bfab99723de3200738d9f58aa56a (patch)
tree58bcc1f8beda07ef1567e7ee88051a1d8180d7c1 /lua/telescope/pickers.lua
parentbaf39e5339aef4f9fff1a10bbccdf929d006bfa5 (diff)
fix(pickers): initial normal mode (#1165)
fix(pickers): opts.default_text and cursor are now correctly set for opts.initial_mode="normal"
Diffstat (limited to 'lua/telescope/pickers.lua')
-rw-r--r--lua/telescope/pickers.lua18
1 files changed, 12 insertions, 6 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 7dbe8a0..9e5f251 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -370,13 +370,19 @@ function Picker:find()
-- 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.default_text then
- self:set_prompt(self.default_text)
- end
-
- if self.initial_mode == "insert" then
+ if self.initial_mode == "insert" or self.initial_mode == "normal" then
+ -- required for set_prompt to work adequately
vim.cmd [[startinsert!]]
- elseif self.initial_mode ~= "normal" then
+ 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
error("Invalid setting for initial_mode: " .. self.initial_mode)
end