Skip to content

Commit 5b53732

Browse files
authored
fix: help window header is minimum width (#2149)
* help: window header is minimum width * help: window header is minimum width
1 parent e99616b commit 5b53732

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lua/nvim-tree/help.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ end
8282
--- @return table arrays of arguments 3-6 for nvim_buf_add_highlight()
8383
--- @return number maximum length of text
8484
local function compute()
85-
local hl = { { "NvimTreeRootFolder", 0, 0, 18 } }
86-
local width = 0
85+
local head_lhs = "nvim-tree mappings"
86+
local head_rhs = "exit: q"
8787

8888
-- formatted lhs and desc from active keymap
8989
local mappings = vim.tbl_map(function(map)
@@ -103,7 +103,16 @@ local function compute()
103103
max_desc = math.max(#l.desc, max_desc)
104104
end
105105

106-
local lines = { ("nvim-tree mappings%sexit: q"):format(string.rep(" ", max_desc + max_lhs - 23)) }
106+
-- increase desc if lines are shorter than the header
107+
max_desc = math.max(max_desc, #head_lhs + #head_rhs - max_lhs)
108+
109+
-- header, not padded
110+
local hl = { { "NvimTreeRootFolder", 0, 0, #head_lhs } }
111+
local lines =
112+
{ ("%s%s%s"):format(head_lhs, string.rep(" ", max_desc + max_lhs - #head_lhs - #head_rhs + 2), head_rhs) }
113+
local width = #lines[1]
114+
115+
-- mappings, left padded 1
107116
local fmt = string.format(" %%-%ds %%-%ds", max_lhs, max_desc)
108117
for i, l in ipairs(mappings) do
109118
-- format in left aligned columns
@@ -112,7 +121,7 @@ local function compute()
112121
width = math.max(#line, width)
113122

114123
-- highlight lhs
115-
table.insert(hl, { "NvimTreeFolderName", i, 0, #l.lhs + 1 })
124+
table.insert(hl, { "NvimTreeFolderName", i, 1, #l.lhs + 1 })
116125
end
117126

118127
return lines, hl, width

0 commit comments

Comments
 (0)