From 47ab113de540d1d1d9cdf7dba76dc60ddd808bb8 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Thu, 25 Jul 2024 01:43:14 +0000 Subject: [PATCH] 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. --- lua/telescope/builtin/__internal.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua index 105b88e..cc1a4c5 100644 --- a/lua/telescope/builtin/__internal.lua +++ b/lua/telescope/builtin/__internal.lua @@ -109,16 +109,18 @@ internal.builtin = function(opts) end actions.close(prompt_bufnr) - if string.match(selection.text, " : ") then - -- Call appropriate function from extensions - local split_string = vim.split(selection.text, " : ") - local ext = split_string[1] - local func = split_string[2] - require("telescope").extensions[ext][func](picker_opts) - else - -- Call appropriate telescope builtin - require("telescope.builtin")[selection.text](picker_opts) - end + vim.schedule(function() + if string.match(selection.text, " : ") then + -- Call appropriate function from extensions + local split_string = vim.split(selection.text, " : ") + local ext = split_string[1] + local func = split_string[2] + require("telescope").extensions[ext][func](picker_opts) + else + -- Call appropriate telescope builtin + require("telescope.builtin")[selection.text](picker_opts) + end + end) end) return true end,