feat: Add mapping to delete avante history via telescope.nvim (#2867)
This commit is contained in:
@@ -69,13 +69,8 @@ function M.open(bufnr, cb)
|
||||
return
|
||||
end
|
||||
Path.history.delete(bufnr, item_id_to_delete) -- bufnr from M.open's scope
|
||||
-- The native provider handles the UI flow; we just need to refresh.
|
||||
M.open(bufnr, cb) -- Re-open the selector to refresh the list
|
||||
end,
|
||||
on_action_cancel = function()
|
||||
-- If the user cancels the open/delete prompt, re-open the history selector.
|
||||
M.open(bufnr, cb)
|
||||
end,
|
||||
on_open = function() M.open(bufnr, cb) end,
|
||||
})
|
||||
current_selector:open()
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ local Utils = require("avante.utils")
|
||||
---@field on_select fun(item_ids: string[] | nil)
|
||||
---@field get_preview_content fun(item_id: string): (string, string) | nil
|
||||
---@field on_delete_item fun(item_id: string): (nil) | nil
|
||||
---@field on_action_cancel fun(): (nil) | nil
|
||||
---@field on_open fun(): (nil) | nil
|
||||
|
||||
---@class avante.ui.Selector
|
||||
---@field provider avante.SelectorProvider
|
||||
@@ -26,7 +26,7 @@ local Utils = require("avante.utils")
|
||||
---@field selected_item_ids string[] | nil
|
||||
---@field get_preview_content fun(item_id: string): (string, string) | nil
|
||||
---@field on_delete_item fun(item_id: string): (nil) | nil
|
||||
---@field on_action_cancel fun(): (nil) | nil
|
||||
---@field on_open fun(): (nil) | nil
|
||||
local Selector = {}
|
||||
Selector.__index = Selector
|
||||
|
||||
@@ -50,7 +50,7 @@ function Selector:new(opts)
|
||||
o.selected_item_ids = opts.selected_item_ids or {}
|
||||
o.get_preview_content = opts.get_preview_content
|
||||
o.on_delete_item = opts.on_delete_item
|
||||
o.on_action_cancel = opts.on_action_cancel
|
||||
o.on_open = opts.on_open
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
@@ -27,16 +27,18 @@ function M.show(selector)
|
||||
local choice = input:lower()
|
||||
if choice == "d" or choice == "delete" then
|
||||
selector.on_delete_item(item.id)
|
||||
-- The native provider handles the UI flow; we just need to refresh.
|
||||
selector.on_open() -- Re-open the selector to refresh the list
|
||||
elseif choice == "" or choice == "o" or choice == "open" then
|
||||
selector.on_select({ item.id })
|
||||
elseif choice == "c" or choice == "cancel" then
|
||||
if type(selector.on_action_cancel) == "function" then
|
||||
selector.on_action_cancel()
|
||||
if type(selector.on_open) == "function" then
|
||||
selector.on_open()
|
||||
else
|
||||
selector.on_select(nil) -- Fallback if on_action_cancel is not defined
|
||||
selector.on_select(nil) -- Fallback if on_open is not defined
|
||||
end
|
||||
else -- c or any other input, treat as cancel
|
||||
selector.on_select(nil) -- Fallback if on_action_cancel is not defined
|
||||
selector.on_select(nil) -- Fallback if on_open is not defined
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
@@ -61,6 +61,49 @@ function M.show(selector)
|
||||
}),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
map("i", "<esc>", require("telescope.actions").close)
|
||||
map("i", "<c-del>", function()
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
|
||||
local selections
|
||||
local multi_selection = picker:get_multi_selection()
|
||||
if #multi_selection ~= 0 then
|
||||
selections = multi_selection
|
||||
else
|
||||
selections = action_state.get_selected_entry()
|
||||
selections = vim.islist(selections) and selections or { selections }
|
||||
end
|
||||
|
||||
local selected_item_ids = vim
|
||||
.iter(selections)
|
||||
:map(function(selection) return selection.value end)
|
||||
:totable()
|
||||
|
||||
vim.ui.input({ prompt = "Remove·selection?·(" .. #selected_item_ids .. " items) [y/N]" }, function(input)
|
||||
if input and input:lower() == "y" then
|
||||
for _, item_id in ipairs(selected_item_ids) do
|
||||
selector.on_delete_item(item_id)
|
||||
end
|
||||
|
||||
local new_items = {}
|
||||
for _, item in ipairs(items) do
|
||||
if not vim.list_contains(selected_item_ids, item.id) then table.insert(new_items, item) end
|
||||
end
|
||||
|
||||
local new_finder = finders.new_table({
|
||||
results = new_items,
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry.id,
|
||||
display = entry.title,
|
||||
ordinal = entry.title,
|
||||
}
|
||||
end,
|
||||
})
|
||||
|
||||
picker:refresh(new_finder, { reset_prompt = true })
|
||||
end
|
||||
end)
|
||||
end, { desc = "delete_selection" })
|
||||
actions.select_default:replace(function()
|
||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user