fix(builtin.pickers): fix wrong picker resuming when using filtering (#2682)

When filtering is applied, `picker:get_index(picker:get_selection_row())` returns index relative to the filtered entry list rather than the original full results. This causes inaccurate indexing into the `cache_pickers` table.
This commit is contained in:
Sofronie Cristian
2023-09-03 23:42:09 +03:00
committed by GitHub
parent dc7f25c810
commit 74be3c3bba
3 changed files with 38 additions and 5 deletions

View File

@@ -1158,12 +1158,25 @@ end
--- This action is not mapped by default and only intended for |builtin.pickers|.
---@param prompt_bufnr number: The prompt bufnr
actions.remove_selected_picker = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local selection_index = current_picker:get_index(current_picker:get_selection_row())
local curr_picker = action_state.get_current_picker(prompt_bufnr)
local curr_entry = action_state.get_selected_entry()
local cached_pickers = state.get_global_key "cached_pickers"
current_picker:delete_selection(function()
if not curr_entry then
return
end
local selection_index, _ = utils.list_find(function(v)
if curr_entry.value == v.value then
return true
end
return false
end, curr_picker.finder.results)
curr_picker:delete_selection(function()
table.remove(cached_pickers, selection_index)
end)
if #cached_pickers == 0 then
actions.close(prompt_bufnr)
end