@@ -80,18 +80,19 @@ local function sort_lhs(a, b)
80
80
end
81
81
82
82
--- Compute all lines for the buffer
83
+ --- @param map table keymap.get_keymap
83
84
--- @return table strings of text
84
85
--- @return table arrays of arguments 3-6 for nvim_buf_add_highlight ()
85
86
--- @return number maximum length of text
86
- local function compute ()
87
+ local function compute (map )
87
88
local head_lhs = " nvim-tree mappings"
88
89
local head_rhs1 = " exit: q"
89
90
local head_rhs2 = string.format (" sort by %s: s" , M .config .sort_by == " key" and " description" or " keymap" )
90
91
91
92
-- formatted lhs and desc from active keymap
92
- local mappings = vim .tbl_map (function (map )
93
- return { lhs = tidy_lhs (map .lhs ), desc = tidy_desc (map .desc ) }
94
- end , keymap . get_keymap () )
93
+ local mappings = vim .tbl_map (function (m )
94
+ return { lhs = tidy_lhs (m .lhs ), desc = tidy_desc (m .desc ) }
95
+ end , map )
95
96
96
97
-- sorter function for mappings
97
98
local sort_fn
@@ -166,8 +167,11 @@ local function open()
166
167
-- close existing, shouldn't be necessary
167
168
close ()
168
169
170
+ -- fetch all mappings
171
+ local map = keymap .get_keymap ()
172
+
169
173
-- text and highlight
170
- local lines , hl , width = compute ()
174
+ local lines , hl , width = compute (map )
171
175
172
176
-- create the buffer
173
177
M .bufnr = vim .api .nvim_create_buf (false , true )
@@ -208,20 +212,20 @@ local function open()
208
212
end
209
213
210
214
-- hardcoded
211
- local keymaps = {
215
+ local help_keymaps = {
212
216
q = { fn = close , desc = " nvim-tree: exit help" },
213
217
[" <Esc>" ] = { fn = close , desc = " nvim-tree: exit help" }, -- hidden
214
218
s = { fn = toggle_sort , desc = " nvim-tree: toggle sorting method" },
215
219
}
216
220
217
221
-- api help binding closes
218
- for _ , map in ipairs (keymap . get_keymap () ) do
219
- if map .callback == api .tree .toggle_help then
220
- keymaps [ map .lhs ] = { fn = close , desc = " nvim-tree: exit help" }
222
+ for _ , m in ipairs (map ) do
223
+ if m .callback == api .tree .toggle_help then
224
+ help_keymaps [ m .lhs ] = { fn = close , desc = " nvim-tree: exit help" }
221
225
end
222
226
end
223
227
224
- for k , v in pairs (keymaps ) do
228
+ for k , v in pairs (help_keymaps ) do
225
229
vim .keymap .set (" n" , k , v .fn , {
226
230
desc = v .desc ,
227
231
buffer = M .bufnr ,
0 commit comments