feat(picker.marks): added <c-x> to delete a mark from the list. See #2390

This commit is contained in:
Folke Lemaitre 2025-11-05 07:42:23 +01:00
parent 20ac8bfc4a
commit 9a04605664
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
3 changed files with 26 additions and 3 deletions

View file

@ -337,6 +337,20 @@ function M.bufdelete(picker)
picker:refresh()
end
function M.mark_delete(picker)
local selected = picker:selected({ fallback = true })
for _, item in ipairs(selected) do
if item.label then
if item.buf then
vim.api.nvim_buf_del_mark(item.buf, item.label)
else
vim.api.nvim_del_mark(item.label)
end
end
end
picker:refresh()
end
function M.git_stage(picker)
local items = picker:selected({ fallback = true })
local first = items[1]

View file

@ -807,6 +807,13 @@ M.marks = {
format = "file",
global = true,
["local"] = true,
win = {
input = {
keys = {
["<c-x>"] = { "mark_delete", mode = { "n", "i" } },
},
},
},
}
---@class snacks.picker.notifications.Config: snacks.picker.Config

View file

@ -58,18 +58,20 @@ function M.history(opts)
end
---@param opts snacks.picker.marks.Config
function M.marks(opts)
---@type snacks.picker.finder
function M.marks(opts, ctx)
local marks = {} ---@type vim.fn.getmarklist.ret.item[]
local current_buf = ctx.filter.current_buf
if opts.global then
vim.list_extend(marks, vim.fn.getmarklist())
end
if opts["local"] then
vim.list_extend(marks, vim.fn.getmarklist(vim.api.nvim_get_current_buf()))
vim.list_extend(marks, vim.fn.getmarklist(current_buf))
end
---@type snacks.picker.finder.Item[]
local items = {}
local bufname = vim.api.nvim_buf_get_name(0)
local bufname = vim.api.nvim_buf_get_name(current_buf)
for _, mark in ipairs(marks) do
local file = mark.file or bufname
local buf = mark.pos[1] and mark.pos[1] > 0 and mark.pos[1] or nil