Deleting marks in picker #1953
-
Hello, how could I delete the selected marks in the marks picker? Is this not available by default and I would have to extend the functionality? It confused me since I can select the marks with |
Beta Was this translation helpful? Give feedback.
Answered by
drowning-cat
Jun 8, 2025
Replies: 1 comment 2 replies
-
Note
Note Deleted items are still selected after Revision 1opts = {
picker = {
sources = {
marks = {
actions = {
delmark = function(picker)
local cursor = picker.list.cursor
local deleted = {}
for _, it in ipairs(picker:selected { fallback = true }) do
local ok = pcall(vim.api.nvim_del_mark, it.label)
if ok then
table.insert(deleted, it)
end
end
picker:close()
local picker_new = Snacks.picker.marks()
picker_new.list:view(cursor - #deleted)
end,
},
win = {
input = {
keys = {
['<C-d>'] = { 'delmark', mode = { 'i', 'n' } },
['d'] = 'delmark', Revision 2opts = {
picker = {
sources = {
marks = {
actions = {
delmark = function(picker, item)
local cursor = picker.list.cursor
local select = picker:selected { fallback = true }
-- stylua: ignore
local delete = vim.iter(select):map(function(it) return it.label end):join ''
local ok
vim.api.nvim_win_call(vim.fn.win_getid(vim.fn.winnr '#'), function()
ok = pcall(vim.cmd.delmark, delete)
picker:find() -- NOTE: Should also be called inside `nvim_win_cal`
end)
if ok then
for _, it in ipairs(select) do
picker.list:unselect(it)
end
else
Snacks.notify.error(string.format('Unable to delete marks: %s', delete))
end
picker.list:view(math.min(cursor, #picker.list.items))
end,
},
win = {
input = {
keys = {
['<C-d>'] = { 'delmark', mode = { 'i', 'n' } },
['d'] = 'delmark', Revision 3opts = {
picker = {
sources = {
marks = {
actions = {
delmark = function(picker)
local selected = picker:selected { fallback = true }
local to_delete = vim
.iter(selected)
:map(function(it)
return it.label
end)
:join ''
vim.api.nvim_win_call(vim.fn.win_getid(vim.fn.winnr '#'), function()
if pcall(vim.cmd.delmark, to_delete) then
-- NOTE: Before `picker.list:set_target`
-- NOTE: Resets `picker.list:is_selected`, `picker.list.selected`
picker.list:set_selected()
picker.list:set_target(math.min(picker.list.cursor, picker:count() - #selected))
picker:find() -- NOTE: Should also be called inside `nvim_win_cal`
else
Snacks.notify.error(string.format('Unable to delete marks: %s', to_delete))
end
end)
end,
},
win = {
input = {
keys = {
['<C-d>'] = { 'delmark', mode = { 'i', 'n' } },
['d'] = 'delmark', |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ciza99
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note
picker:find
doesn't work as expected with thevim_marks
finder because it is bound to the current window.Note
Deleted items are still selected after
picker:find
.Revision 1