fix(snacks): cleaner way to adjust keys preset

This commit is contained in:
Folke Lemaitre 2024-11-19 07:31:28 +01:00
parent 0bb1da6d57
commit 9c31004365
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 29 additions and 11 deletions

View file

@ -152,6 +152,9 @@ return {
"nvimdev/dashboard-nvim", "nvimdev/dashboard-nvim",
optional = true, optional = true,
opts = function(_, opts) opts = function(_, opts)
if not vim.tbl_get(opts, "config", "center") then
return
end
local projects = { local projects = {
action = pick, action = pick,
desc = " Projects", desc = " Projects",
@ -165,4 +168,17 @@ return {
table.insert(opts.config.center, 3, projects) table.insert(opts.config.center, 3, projects)
end, end,
}, },
{
"folke/snacks.nvim",
optional = true,
opts = function(_, opts)
table.insert(opts.dashboard.preset.keys, 3, {
action = pick,
desc = "Projects",
icon = "",
key = "p",
})
end,
},
} }

View file

@ -319,17 +319,19 @@ return {
]], ]],
---@param keys snacks.dashboard.Item[] -- stylua: ignore
keys = function(keys) ---@type snacks.dashboard.Item[]
-- add LazyExtra before Lazy keys = {
for k, key in ipairs(keys) do { icon = "", key = "f", desc = "Find File", action = ":lua Snacks.dashboard.pick('files')" },
if key.action == ":Lazy" then { icon = "", key = "n", desc = "New File", action = ":ene | startinsert" },
key.key = "l" -- we don't have multiple panes, so `l` is free { icon = "", key = "g", desc = "Find Text", action = ":lua Snacks.dashboard.pick('live_grep')" },
table.insert(keys, k, { icon = "", desc = "Lazy Extras", action = ":LazyExtras", key = "x" }) { icon = "", key = "r", desc = "Recent Files", action = ":lua Snacks.dashboard.pick('oldfiles')" },
break { icon = "", key = "c", desc = "Config", action = ":lua Snacks.dashboard.pick('files', {cwd = vim.fn.stdpath('config')})" },
end { icon = "", key = "s", desc = "Restore Session", section = "session" },
end { icon = "", key = "x", desc = "Lazy Extras", action = ":LazyExtras" },
end, { icon = "󰒲 ", key = "l", desc = "Lazy", action = ":Lazy" },
{ icon = "", key = "q", desc = "Quit", action = ":qa" },
},
}, },
}, },
}, },