From 20a37e43bb43c74c6091f9fea6551af0964ad45a Mon Sep 17 00:00:00 2001 From: Sofronie Cristian <53446505+cristiansofronie@users.noreply.github.com> Date: Mon, 4 Sep 2023 21:05:59 +0300 Subject: [PATCH] fix(telescope.state.get_existing_prompts): it should only return keys that are numbers (#2684) * fix(telescope.state.get_existing_prompts): it should only return keys that are numbers * Table keys not table values should be numbers * Rename get_existing_prompts to get_existing_prompt_bufnrs and make the impl more efficient --- lua/telescope/pickers.lua | 2 +- lua/telescope/state.lua | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 143af11..3c2c2d4 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -1227,7 +1227,7 @@ end --- Close all open Telescope pickers function Picker:close_existing_pickers() - for _, prompt_bufnr in ipairs(state.get_existing_prompts()) do + for _, prompt_bufnr in ipairs(state.get_existing_prompt_bufnrs()) do pcall(actions.close, prompt_bufnr) end end diff --git a/lua/telescope/state.lua b/lua/telescope/state.lua index 6a06eb1..a3e6d85 100644 --- a/lua/telescope/state.lua +++ b/lua/telescope/state.lua @@ -24,8 +24,16 @@ function state.clear_status(prompt_bufnr) state.set_status(prompt_bufnr, nil) end -function state.get_existing_prompts() - return vim.tbl_keys(TelescopeGlobalState) +function state.get_existing_prompt_bufnrs() + local prompt_bufnrs = {} + + for key, _ in pairs(TelescopeGlobalState) do + if type(key) == "number" then + table.insert(prompt_bufnrs, key) + end + end + + return prompt_bufnrs end return state