fix(pickers): initial normal mode (#1165)

fix(pickers): opts.default_text and cursor are now correctly set for opts.initial_mode="normal"
This commit is contained in:
fdschmidt93
2021-09-01 17:09:26 +02:00
committed by GitHub
parent baf39e5339
commit 8710baa6fb

View File

@@ -370,13 +370,19 @@ function Picker:find()
-- TODO(async): I wonder if this should actually happen _before_ we nvim_buf_attach. -- 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. -- 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 if self.default_text then
self:set_prompt(self.default_text) self:set_prompt(self.default_text)
end end
if self.initial_mode == "normal" then
if self.initial_mode == "insert" then -- otherwise (i) insert mode exitted faster than `picker:set_prompt`; (ii) cursor on wrong pos
vim.cmd [[startinsert!]] await_schedule(function()
elseif self.initial_mode ~= "normal" then vim.cmd [[stopinsert]]
end)
end
else
error("Invalid setting for initial_mode: " .. self.initial_mode) error("Invalid setting for initial_mode: " .. self.initial_mode)
end end