mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(dashboard): allow opts.preset.keys to be a function with default keymaps as arg
This commit is contained in:
parent
4ff08f1c4d
commit
b7775ec879
1 changed files with 12 additions and 3 deletions
|
@ -78,9 +78,11 @@ local defaults = {
|
|||
-- Defaults to a picker that supports `fzf-lua`, `telescope.nvim` and `mini.pick`
|
||||
---@type fun(cmd:string, opts:table)|nil
|
||||
pick = nil,
|
||||
-- Used by the `keys` section to show keymaps
|
||||
-- Used by the `keys` section to show keymaps.
|
||||
-- Set your curstom keymaps here.
|
||||
-- When using a function, the `items` argument are the default keymaps.
|
||||
-- stylua: ignore
|
||||
---@type snacks.dashboard.Item[]
|
||||
---@type snacks.dashboard.Item[]|fun(items:snacks.dashboard.Item[]):snacks.dashboard.Item[]?
|
||||
keys = {
|
||||
{ icon = " ", key = "f", desc = "Find File", action = ":lua Snacks.dashboard.pick('files')" },
|
||||
{ icon = " ", key = "n", desc = "New File", action = ":ene | startinsert" },
|
||||
|
@ -852,7 +854,14 @@ end
|
|||
---@return snacks.dashboard.Gen
|
||||
function M.sections.keys()
|
||||
return function(self)
|
||||
return vim.deepcopy(self.opts.preset.keys)
|
||||
local keys = self.opts.preset.keys
|
||||
if type(keys) == "function" then
|
||||
local default_keys = vim.deepcopy(defaults.preset.keys --[[@as snacks.dashboard.Item[] ]])
|
||||
keys = keys(default_keys) or default_keys
|
||||
else
|
||||
keys = vim.deepcopy(keys)
|
||||
end
|
||||
return vim.deepcopy(keys)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue