Skip to content

fix: help window header is minimum width #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lua/nvim-tree/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ end
--- @return table arrays of arguments 3-6 for nvim_buf_add_highlight()
--- @return number maximum length of text
local function compute()
local hl = { { "NvimTreeRootFolder", 0, 0, 18 } }
local width = 0
local head_lhs = "nvim-tree mappings"
local head_rhs = "exit: q"

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

local lines = { ("nvim-tree mappings%sexit: q"):format(string.rep(" ", max_desc + max_lhs - 23)) }
-- increase desc if lines are shorter than the header
max_desc = math.max(max_desc, #head_lhs + #head_rhs - max_lhs)

-- header, not padded
local hl = { { "NvimTreeRootFolder", 0, 0, #head_lhs } }
local lines =
{ ("%s%s%s"):format(head_lhs, string.rep(" ", max_desc + max_lhs - #head_lhs - #head_rhs + 2), head_rhs) }
local width = #lines[1]

-- mappings, left padded 1
local fmt = string.format(" %%-%ds %%-%ds", max_lhs, max_desc)
for i, l in ipairs(mappings) do
-- format in left aligned columns
Expand All @@ -112,7 +121,7 @@ local function compute()
width = math.max(#line, width)

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

return lines, hl, width
Expand Down