feat(dashboard): allow items to be hidden, but still create the keymaps etc

This commit is contained in:
Folke Lemaitre 2024-12-01 17:41:10 +01:00
parent 0043fa9ee1
commit 7a47eb76df
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -23,6 +23,7 @@ math.randomseed(os.time())
---@field section? string the name of a section to include. See `Snacks.dashboard.sections` ---@field section? string the name of a section to include. See `Snacks.dashboard.sections`
---@field [string] any section options ---@field [string] any section options
---@field key? string shortcut key ---@field key? string shortcut key
---@field hidden? boolean when `true`, the item will not be shown, but the key will still be assigned
---@field autokey? boolean automatically assign a numerical key ---@field autokey? boolean automatically assign a numerical key
---@field label? string ---@field label? string
---@field desc? string ---@field desc? string
@ -526,7 +527,7 @@ function D:find(pos, from)
local ret ---@type snacks.dashboard.Item? local ret ---@type snacks.dashboard.Item?
for _, item in ipairs(self.items) do for _, item in ipairs(self.items) do
if item._.pane == pane and item.action then if item._ and item._.pane == pane and item.action then
if ret and pos[1] < from[1] and item._.row > pos[1] then if ret and pos[1] < from[1] and item._.row > pos[1] then
break break
end end
@ -545,11 +546,13 @@ function D:layout()
math.max(1, math.floor((self._size.width + self.opts.pane_gap) / (self.opts.width + self.opts.pane_gap))) math.max(1, math.floor((self._size.width + self.opts.pane_gap) / (self.opts.width + self.opts.pane_gap)))
self.panes = {} ---@type snacks.dashboard.Item[][] self.panes = {} ---@type snacks.dashboard.Item[][]
for _, item in ipairs(self.items) do for _, item in ipairs(self.items) do
if not item.hidden then
local pane = item.pane or 1 local pane = item.pane or 1
pane = math.fmod(pane - 1, max_panes) + 1 -- distribute panes evenly pane = math.fmod(pane - 1, max_panes) + 1 -- distribute panes evenly
self.panes[pane] = self.panes[pane] or {} self.panes[pane] = self.panes[pane] or {}
table.insert(self.panes[pane], item) table.insert(self.panes[pane], item)
end end
end
for p = 1, math.max(unpack(vim.tbl_keys(self.panes))) or 1 do for p = 1, math.max(unpack(vim.tbl_keys(self.panes))) or 1 do
self.panes[p] = self.panes[p] or {} self.panes[p] = self.panes[p] or {}
end end