82
82
--- @return table arrays of arguments 3-6 for nvim_buf_add_highlight ()
83
83
--- @return number maximum length of text
84
84
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 "
87
87
88
88
-- formatted lhs and desc from active keymap
89
89
local mappings = vim .tbl_map (function (map )
@@ -103,7 +103,16 @@ local function compute()
103
103
max_desc = math.max (# l .desc , max_desc )
104
104
end
105
105
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
107
116
local fmt = string.format (" %%-%ds %%-%ds" , max_lhs , max_desc )
108
117
for i , l in ipairs (mappings ) do
109
118
-- format in left aligned columns
@@ -112,7 +121,7 @@ local function compute()
112
121
width = math.max (# line , width )
113
122
114
123
-- highlight lhs
115
- table.insert (hl , { " NvimTreeFolderName" , i , 0 , # l .lhs + 1 })
124
+ table.insert (hl , { " NvimTreeFolderName" , i , 1 , # l .lhs + 1 })
116
125
end
117
126
118
127
return lines , hl , width
0 commit comments