Skip to content

Commit 47ab113

Browse files
authored
fix(builtin.builtin): schedule opening next picker (#3222)
Without scheduling, lots of vim state will be related to the builtin picker when the new picker is opened despite closing the builtin picker first and then opening a new picker. This impacts state like `vim.fn.mode()`. If the builtin picker was closed in insert mode, the closing action _should_ put you back in normal mode. But without scheduling, the next picker is opened before it does. So doing `vim.fn.mode()` in the subsequent picker will tell you, you're still in insert mode. Typically, when chaining pickers, you want the pre-telescope state, making the transitions between pickers seemless.
1 parent d39ad2a commit 47ab113

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lua/telescope/builtin/__internal.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,18 @@ internal.builtin = function(opts)
109109
end
110110

111111
actions.close(prompt_bufnr)
112-
if string.match(selection.text, " : ") then
113-
-- Call appropriate function from extensions
114-
local split_string = vim.split(selection.text, " : ")
115-
local ext = split_string[1]
116-
local func = split_string[2]
117-
require("telescope").extensions[ext][func](picker_opts)
118-
else
119-
-- Call appropriate telescope builtin
120-
require("telescope.builtin")[selection.text](picker_opts)
121-
end
112+
vim.schedule(function()
113+
if string.match(selection.text, " : ") then
114+
-- Call appropriate function from extensions
115+
local split_string = vim.split(selection.text, " : ")
116+
local ext = split_string[1]
117+
local func = split_string[2]
118+
require("telescope").extensions[ext][func](picker_opts)
119+
else
120+
-- Call appropriate telescope builtin
121+
require("telescope.builtin")[selection.text](picker_opts)
122+
end
123+
end)
122124
end)
123125
return true
124126
end,

0 commit comments

Comments
 (0)