feat(picker.actions): allow selecting the visual selection with <Tab>

This commit is contained in:
Folke Lemaitre 2025-01-30 22:45:56 +01:00
parent 18de5bb238
commit 96c76c6d9d
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 15 additions and 2 deletions

View file

@ -238,8 +238,8 @@ local defaults = {
["j"] = "list_down",
["k"] = "list_up",
["q"] = "close",
["<Tab>"] = "select_and_next",
["<S-Tab>"] = "select_and_prev",
["<Tab>"] = { "select_and_next", mode = { "n", "x" } },
["<S-Tab>"] = { "select_and_prev", mode = { "n", "x" } },
["<Down>"] = "list_down",
["<Up>"] = "list_up",
["<a-d>"] = "inspect",

View file

@ -296,6 +296,19 @@ end
-- Toggle selection of current item
---@param item? snacks.picker.Item
function M:select(item)
if item == nil and vim.fn.mode():find("^[vV]") and vim.api.nvim_get_current_buf() == self.win.buf then
-- stop visual mode
vim.cmd("normal! " .. vim.fn.mode():sub(1, 1))
local from = vim.api.nvim_buf_get_mark(0, "<")
local to = vim.api.nvim_buf_get_mark(0, ">")
for i = math.min(from[1], to[1]), math.max(from[1], to[1]) do
local it = self:get(self:row2idx(i))
if it then
self:select(it)
end
end
return
end
item = item or self:current()
if not item then
return