Skip to content

Commit 73fdc79

Browse files
committed
fix(alpha): patch alpha button function until resolved upstream
PR fix opened upstream: goolord/alpha-nvim#271
1 parent 708032a commit 73fdc79

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lua/astronvim/plugins/alpha.lua

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,37 @@ return {
7777
opts = function()
7878
local dashboard = require "alpha.themes.dashboard"
7979

80-
local orig_button = dashboard.button -- customize button function
81-
dashboard.button = function(...)
82-
return vim.tbl_deep_extend("force", orig_button(...), {
83-
opts = { cursor = -2, width = 36, hl = "DashboardCenter", hl_shortcut = "DashboardShortcut" },
84-
})
85-
end
8680
dashboard.leader = "LDR"
8781

82+
--- @param shortcut string Shortcut string of a button mapping
83+
--- @param desc string Real text description of the mapping
84+
--- @param rhs string? Righthand side of mapping if defining a new mapping (_optional_)
85+
--- @param map_opts table? `keymap.set` options used during keymap creating (_optional_)
86+
dashboard.button = function(shortcut, desc, rhs, map_opts)
87+
-- HACK: fixes leader customization, remove after fixed upstream
88+
-- https://github.com/goolord/alpha-nvim/pull/271
89+
local lhs = shortcut:gsub("%s", ""):gsub(dashboard.leader, "<Leader>")
90+
local default_map_opts = { noremap = true, silent = true, nowait = true, desc = desc }
91+
92+
return {
93+
type = "button",
94+
val = desc,
95+
on_press = function()
96+
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(rhs or lhs .. "<Ignore>", true, false, true), "t", false)
97+
end,
98+
opts = {
99+
position = "center",
100+
shortcut = shortcut,
101+
cursor = -2,
102+
width = 36,
103+
align_shortcut = "right",
104+
hl = "DashboardCenter",
105+
hl_shortcut = "DashboardShortcut",
106+
keymap = rhs and { "n", lhs, rhs, require("astrocore").extend_tbl(default_map_opts, map_opts) },
107+
},
108+
}
109+
end
110+
88111
dashboard.section.header.val = {
89112
" █████ ███████ ████████ ██████ ██████",
90113
"██ ██ ██ ██ ██ ██ ██ ██",

0 commit comments

Comments
 (0)