Skip to content

Commit

Permalink
fix(telescope.state.get_existing_prompts): it should only return keys…
Browse files Browse the repository at this point in the history
… 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

(cherry picked from commit 20a37e4)
  • Loading branch information
cristiansofronie authored and Conni2461 committed Sep 5, 2023
1 parent 573a8b2 commit 9a9ca52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,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
Expand Down
12 changes: 10 additions & 2 deletions lua/telescope/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a9ca52

Please sign in to comment.