feat(picker.smart): add bufdelete actions from buffers picker (#679)

## Description

This enables the ability to delete buffers directly from the `smart`
picker (or other combined pickers) by adding a check + warning to the
`bufdelete` action (ensuring it only operates on buffer items), and
adding the same `dd` and `<c-x>` mappings as the `buffers` picker.

## Related Issue(s)

TBD... searching.

## Screenshots


https://github.com/user-attachments/assets/6c5c4b5e-74ed-4778-9f31-a714f7da1853
This commit is contained in:
Jorge Villalobos 2025-01-21 02:43:37 -05:00 committed by GitHub
parent 3af7a472d7
commit 67fbab1bf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -118,10 +118,20 @@ function M.toggle_preview(picker)
end
function M.bufdelete(picker)
local non_buf_delete_requested = false
for _, item in ipairs(picker:selected({ fallback = true })) do
Snacks.bufdelete.delete(item.buf)
if item.buf then
Snacks.bufdelete.delete(item.buf)
else
non_buf_delete_requested = true
end
picker.list:unselect(item)
end
if non_buf_delete_requested then
Snacks.notify.warn("Only open buffers can be deleted", { title = "Snacks Picker" })
end
local cursor = picker.list.cursor
picker:find({
on_done = function()

View file

@ -564,6 +564,15 @@ M.smart = {
format = "file",
-- sort the results even when the filter is empty (frecency)
matcher = { sort_empty = true },
win = {
input = {
keys = {
["dd"] = "bufdelete",
["<c-x>"] = { "bufdelete", mode = { "n", "i" } },
},
},
list = { keys = { ["dd"] = "bufdelete" } },
},
}
M.spelling = {