1+ local function titleize (action )
2+ if type (action ) ~= ' string' then
3+ return nil
4+ end
5+ if action == ' ' then
6+ return nil
7+ end
8+ local out = action :gsub (' _' , ' ' )
9+ return out :sub (1 , 1 ):upper () .. out :sub (2 )
10+ end
11+
12+ local function action_desc (action )
13+ if type (action ) == ' string' then
14+ return titleize (action )
15+ end
16+ if type (action ) == ' function' then
17+ return ' Custom action'
18+ end
19+ if type (action ) ~= ' table' then
20+ return nil
21+ end
22+
23+ if action .desc then
24+ return action .desc
25+ end
26+
27+ if action .action then
28+ return action_desc (action .action )
29+ end
30+
31+ local is_list = vim .islist or vim .tbl_islist
32+ if is_list and is_list (action ) then
33+ local parts = {}
34+ for _ , item in ipairs (action ) do
35+ local desc = action_desc (item )
36+ if desc then
37+ parts [# parts + 1 ] = desc
38+ end
39+ end
40+ if # parts > 0 then
41+ return table.concat (parts , ' , ' )
42+ end
43+ end
44+
45+ return nil
46+ end
47+
48+ local function add_desc_to_picker_keys (opts )
49+ local function apply (keys )
50+ if not keys then
51+ return
52+ end
53+ for _ , spec in pairs (keys ) do
54+ if type (spec ) == ' table' and spec .desc == nil then
55+ local action = spec [1 ] or spec [2 ]
56+ local desc = action_desc (action )
57+ if desc then
58+ spec .desc = desc
59+ end
60+ end
61+ end
62+ end
63+
64+ for _ , win in pairs (opts .win or {}) do
65+ apply (win .keys )
66+ end
67+ for _ , source in pairs (opts .sources or {}) do
68+ if type (source ) == ' table' and source .win then
69+ for _ , win in pairs (source .win ) do
70+ apply (win .keys )
71+ end
72+ end
73+ end
74+ end
75+
76+ local function ensure_dashboard_desc_keymaps ()
77+ if vim .g .snacks_dashboard_desc_keymaps then
78+ return
79+ end
80+ vim .g .snacks_dashboard_desc_keymaps = true
81+
82+ local group = vim .api .nvim_create_augroup (' snacks_dashboard_desc' , { clear = true })
83+ vim .api .nvim_create_autocmd (' FileType' , {
84+ group = group ,
85+ pattern = ' snacks_dashboard' ,
86+ callback = function (ev )
87+ vim .keymap .set (' n' , ' q' , ' <cmd>bd<cr>' , { buffer = ev .buf , silent = true , desc = ' Close dashboard' })
88+ local cfg = vim .api .nvim_win_get_config (0 )
89+ if cfg and cfg .relative ~= ' ' then
90+ vim .keymap .set (' n' , ' <esc>' , ' <cmd>bd<cr>' , { buffer = ev .buf , silent = true , desc = ' Close dashboard' })
91+ end
92+ end ,
93+ })
94+ end
95+
196return {
297 ' folke/snacks.nvim' ,
398 priority = 1000 ,
@@ -8,16 +103,104 @@ return {
8103 -- or leave it empty to use the default settings
9104 -- refer to the configuration section below
10105 bigfile = { enabled = true },
11- dashboard = { enabled = true },
106+ dashboard = {
107+ enabled = true ,
108+ config = function ()
109+ ensure_dashboard_desc_keymaps ()
110+ end ,
111+ },
12112 explorer = { enabled = true },
13113 indent = { enabled = true },
14114 input = { enabled = true },
15- picker = { enabled = true },
16- notifier = { enabled = true },
115+ picker = {
116+ enabled = true ,
117+ config = function (opts )
118+ add_desc_to_picker_keys (opts )
119+ end ,
120+ },
121+ notifier = {
122+ enabled = true ,
123+ top_down = false ,
124+ },
17125 quickfile = { enabled = true },
18126 scope = { enabled = true },
19127 scroll = { enabled = false },
20128 statuscolumn = { enabled = false },
21129 words = { enabled = true },
130+
131+ styles = {
132+ input = {
133+ keys = {
134+ n_esc = {
135+ ' <esc>' ,
136+ { ' cmp_close' , ' cancel' },
137+ mode = ' n' ,
138+ expr = true ,
139+ desc = ' Cancel input' ,
140+ },
141+ i_esc = {
142+ ' <esc>' ,
143+ { ' cmp_close' , ' stopinsert' },
144+ mode = ' i' ,
145+ expr = true ,
146+ desc = ' Cancel input' ,
147+ },
148+ i_cr = {
149+ ' <cr>' ,
150+ { ' cmp_accept' , ' confirm' },
151+ mode = { ' i' , ' n' },
152+ expr = true ,
153+ desc = ' Confirm input' ,
154+ },
155+ i_tab = {
156+ ' <tab>' ,
157+ { ' cmp_select_next' , ' cmp' },
158+ mode = ' i' ,
159+ expr = true ,
160+ desc = ' Next completion' ,
161+ },
162+ i_ctrl_w = {
163+ ' <c-w>' ,
164+ ' <c-s-w>' ,
165+ mode = ' i' ,
166+ expr = true ,
167+ desc = ' Delete word' ,
168+ },
169+ i_up = {
170+ ' <up>' ,
171+ { ' hist_up' },
172+ mode = { ' i' , ' n' },
173+ desc = ' History up' ,
174+ },
175+ i_down = {
176+ ' <down>' ,
177+ { ' hist_down' },
178+ mode = { ' i' , ' n' },
179+ desc = ' History down' ,
180+ },
181+ q = { ' q' , ' cancel' , desc = ' Cancel input' },
182+ },
183+ },
184+ terminal = {
185+ keys = {
186+ q = { ' q' , ' hide' , desc = ' Hide terminal' },
187+ gf = {
188+ ' gf' ,
189+ function (self )
190+ local f = vim .fn .findfile (vim .fn .expand ' <cfile>' , ' **' )
191+ if f == ' ' then
192+ Snacks .notify .warn ' No file under cursor'
193+ else
194+ self :hide ()
195+ vim .schedule (function ()
196+ vim .cmd (' e ' .. f )
197+ end )
198+ end
199+ end ,
200+ desc = ' Open file under cursor' ,
201+ },
202+ },
203+ },
204+ },
22205 },
23206}
0 commit comments