fix(help ui): adapt to new bindings and fix code lint/format

This commit is contained in:
kiyan
2021-07-01 10:35:01 +02:00
parent 7abec5e594
commit a01a33f9a8

View File

@@ -370,35 +370,45 @@ local M = {}
function M.draw_help() function M.draw_help()
local help_lines = {'HELP'} local help_lines = {'HELP'}
local help_hl = {{'NvimTreeRootFolder', 0, 0, string.len('HELP')}} local help_hl = {{'NvimTreeRootFolder', 0, 0, #help_lines[1]}}
local bindings = view.View.bindings local bindings = view.View.bindings
local processed = {} local processed = {}
for i, v in pairs(bindings) do for _, b in pairs(bindings) do
if v:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then local cb = b.cb
v = v:match("'[^']+'[^']*$") local key = b.key
v = v:match("'[^']+'") if cb:sub(1,35) == view.nvim_tree_callback('test'):sub(1,35) then
table.insert(processed,{i,v,true}) cb = cb:match("'[^']+'[^']*$")
cb = cb:match("'[^']+'")
table.insert(processed, {key, cb, true})
else else
v = '"' .. v .. '"' cb = '"' .. cb .. '"'
table.insert(processed,{i,v,false}) table.insert(processed, {key, cb, false})
end end
end end
table.sort(processed, function(a,b) table.sort(processed, function(a,b)
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]) 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])
end) end)
local i, v, builtin
for num, val in pairs(processed) do local num = 0
i = val[1] for _, val in pairs(processed) do
v = val[2] local keys = type(val[1]) == "string" and {val[1]} or val[1]
builtin = val[3] local map_name = val[2]
local bind_string = string.format("%6s : %s",i,v) local builtin = val[3]
for _, key in pairs(keys) do
num = num + 1
local bind_string = string.format("%6s : %s", key, map_name)
table.insert(help_lines, bind_string) table.insert(help_lines, bind_string)
local hl_len = math.max(6,#i)+2
local hl_len = math.max(6, string.len(key)) + 2
table.insert(help_hl, {'NvimTreeFolderName', num, 0, hl_len}) table.insert(help_hl, {'NvimTreeFolderName', num, 0, hl_len})
if not builtin then if not builtin then
table.insert(help_hl, {'NvimTreeFileRenamed', num, hl_len, -1}) table.insert(help_hl, {'NvimTreeFileRenamed', num, hl_len, -1})
end end
end end
end
return help_lines, help_hl return help_lines, help_hl
end end