Skip to content

Commit a01a33f

Browse files
committed
fix(help ui): adapt to new bindings and fix code lint/format
1 parent 7abec5e commit a01a33f

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

lua/nvim-tree/renderer.lua

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -370,33 +370,43 @@ local M = {}
370370

371371
function M.draw_help()
372372
local help_lines = {'HELP'}
373-
local help_hl = {{'NvimTreeRootFolder', 0, 0, string.len('HELP')}}
373+
local help_hl = {{'NvimTreeRootFolder', 0, 0, #help_lines[1]}}
374374
local bindings = view.View.bindings
375375
local processed = {}
376-
for i, v in pairs(bindings) do
377-
if v:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then
378-
v = v:match("'[^']+'[^']*$")
379-
v = v:match("'[^']+'")
380-
table.insert(processed,{i,v,true})
376+
for _, b in pairs(bindings) do
377+
local cb = b.cb
378+
local key = b.key
379+
if cb:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then
380+
cb = cb:match("'[^']+'[^']*$")
381+
cb = cb:match("'[^']+'")
382+
table.insert(processed, {key, cb, true})
381383
else
382-
v = '"' .. v .. '"'
383-
table.insert(processed,{i,v,false})
384+
cb = '"' .. cb .. '"'
385+
table.insert(processed, {key, cb, false})
384386
end
385387
end
386-
table.sort(processed,function(a,b)
387-
return (a[3]==b[3] and (a[2]<b[2] or (a[2]==b[2] and #a[1]<#b[1]))) or (a[3] and not b[3])
388+
table.sort(processed, function(a,b)
389+
return (a[3] == b[3]
390+
and (a[2] < b[2] or (a[2] == b[2] and #a[1] < #b[1])))
391+
or (a[3] and not b[3])
388392
end)
389-
local i, v, builtin
390-
for num, val in pairs(processed) do
391-
i = val[1]
392-
v = val[2]
393-
builtin = val[3]
394-
local bind_string = string.format("%6s : %s",i,v)
395-
table.insert(help_lines,bind_string)
396-
local hl_len = math.max(6,#i)+2
397-
table.insert(help_hl,{'NvimTreeFolderName', num, 0, hl_len})
398-
if not builtin then
399-
table.insert(help_hl,{'NvimTreeFileRenamed', num, hl_len, -1})
393+
394+
local num = 0
395+
for _, val in pairs(processed) do
396+
local keys = type(val[1]) == "string" and {val[1]} or val[1]
397+
local map_name = val[2]
398+
local builtin = val[3]
399+
for _, key in pairs(keys) do
400+
num = num + 1
401+
local bind_string = string.format("%6s : %s", key, map_name)
402+
table.insert(help_lines, bind_string)
403+
404+
local hl_len = math.max(6, string.len(key)) + 2
405+
table.insert(help_hl, {'NvimTreeFolderName', num, 0, hl_len})
406+
407+
if not builtin then
408+
table.insert(help_hl, {'NvimTreeFileRenamed', num, hl_len, -1})
409+
end
400410
end
401411
end
402412
return help_lines, help_hl

0 commit comments

Comments
 (0)