feat: Add mapping to delete avante history via snacks.nvim (#2868)
This commit is contained in:
@@ -8,23 +8,26 @@ function M.show(selector)
|
|||||||
Utils.error("Snacks is not set up. Please install and set up Snacks to use it as a file selector.")
|
Utils.error("Snacks is not set up. Please install and set up Snacks to use it as a file selector.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local finder_items = {}
|
local function snacks_finder()
|
||||||
for i, item in ipairs(selector.items) do
|
local items = {}
|
||||||
if not vim.list_contains(selector.selected_item_ids, item.id) then
|
for i, item in ipairs(selector.items) do
|
||||||
table.insert(finder_items, {
|
if not vim.list_contains(selector.selected_item_ids, item.id) then
|
||||||
formatted = item.title,
|
table.insert(items, {
|
||||||
text = item.title,
|
formatted = item.title,
|
||||||
item = item,
|
text = item.title,
|
||||||
idx = i,
|
item = item,
|
||||||
preview = selector.get_preview_content and (function()
|
idx = i,
|
||||||
local content, filetype = selector.get_preview_content(item.id)
|
preview = selector.get_preview_content and (function()
|
||||||
return {
|
local content, filetype = selector.get_preview_content(item.id)
|
||||||
text = content,
|
return {
|
||||||
ft = filetype,
|
text = content,
|
||||||
}
|
ft = filetype,
|
||||||
end)() or nil,
|
}
|
||||||
})
|
end)() or nil,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return items
|
||||||
end
|
end
|
||||||
|
|
||||||
local completed = false
|
local completed = false
|
||||||
@@ -32,7 +35,8 @@ function M.show(selector)
|
|||||||
---@diagnostic disable-next-line: undefined-global
|
---@diagnostic disable-next-line: undefined-global
|
||||||
Snacks.picker.pick(vim.tbl_deep_extend("force", {
|
Snacks.picker.pick(vim.tbl_deep_extend("force", {
|
||||||
source = "select",
|
source = "select",
|
||||||
items = finder_items,
|
live = true,
|
||||||
|
finder = snacks_finder,
|
||||||
---@diagnostic disable-next-line: undefined-global
|
---@diagnostic disable-next-line: undefined-global
|
||||||
format = Snacks.picker.format.ui_select({ format_item = function(item, _) return item.title end }),
|
format = Snacks.picker.format.ui_select({ format_item = function(item, _) return item.title end }),
|
||||||
title = selector.title,
|
title = selector.title,
|
||||||
@@ -53,6 +57,31 @@ function M.show(selector)
|
|||||||
completed = true
|
completed = true
|
||||||
vim.schedule(function() selector.on_select(nil) end)
|
vim.schedule(function() selector.on_select(nil) end)
|
||||||
end,
|
end,
|
||||||
|
actions = {
|
||||||
|
delete_selection = function(picker)
|
||||||
|
local selections = picker:selected({ fallback = true })
|
||||||
|
if #selections == 0 then return end
|
||||||
|
vim.ui.input({ prompt = "Remove·selection?·(" .. #selections .. " items) [y/N]" }, function(input)
|
||||||
|
if input and input:lower() == "y" then
|
||||||
|
for _, selection in ipairs(selections) do
|
||||||
|
selector.on_delete_item(selection.item.id)
|
||||||
|
for i, item in ipairs(selector.items) do
|
||||||
|
if item.id == selection.item.id then table.remove(selector.items, i) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
picker:refresh()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
win = {
|
||||||
|
input = {
|
||||||
|
keys = {
|
||||||
|
["<C-DEL>"] = { "delete_selection", mode = { "i", "n" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}, selector.provider_opts))
|
}, selector.provider_opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user