@@ -11,6 +11,8 @@ local WIN_HL = table.concat({
11
11
" CursorLine:NvimTreeCursorLine" ,
12
12
}, " ," )
13
13
14
+ local namespace_help_id = vim .api .nvim_create_namespace (" NvimTreeHelp" )
15
+
14
16
local M = {
15
17
config = {},
16
18
82
84
83
85
--- Compute all lines for the buffer
84
86
--- @param map table keymap.get_keymap
85
- --- @return table strings of text
86
- --- @return table arrays of arguments 3-6 for nvim_buf_add_highlight ()
87
+ --- @return string[] lines of text
88
+ --- @return HighlightRangeArgs[] hl_range_args for lines
87
89
--- @return number maximum length of text
88
90
local function compute (map )
89
91
local head_lhs = " nvim-tree mappings"
@@ -130,10 +132,10 @@ local function compute(map)
130
132
local width = # lines [1 ]
131
133
132
134
-- header highlight, assume one character keys
133
- local hl = {
134
- { " NvimTreeFolderName" , 0 , 0 , # head_lhs },
135
- { " NvimTreeFolderName" , 0 , width - 1 , width },
136
- { " NvimTreeFolderName" , 1 , width - 1 , width },
135
+ local hl_range_args = {
136
+ { higroup = " NvimTreeFolderName" , start = { 0 , 0 , }, finish = { 0 , # head_lhs , }, },
137
+ { higroup = " NvimTreeFolderName" , start = { 0 , width - 1 , }, finish = { 0 , width , }, },
138
+ { higroup = " NvimTreeFolderName" , start = { 1 , width - 1 , }, finish = { 1 , width , }, },
137
139
}
138
140
139
141
-- mappings, left padded 1
@@ -145,10 +147,10 @@ local function compute(map)
145
147
width = math.max (# line , width )
146
148
147
149
-- highlight lhs
148
- table.insert (hl , { " NvimTreeFolderName" , i + 1 , 1 , # l .lhs + 1 })
150
+ table.insert (hl_range_args , { higroup = " NvimTreeFolderName" , start = { i + 1 , 1 , }, finish = { i + 1 , # l .lhs + 1 , }, })
149
151
end
150
152
151
- return lines , hl , width
153
+ return lines , hl_range_args , width
152
154
end
153
155
154
156
--- close the window and delete the buffer, if they exist
@@ -172,7 +174,7 @@ local function open()
172
174
local map = keymap .get_keymap ()
173
175
174
176
-- text and highlight
175
- local lines , hl , width = compute (map )
177
+ local lines , hl_range_args , width = compute (map )
176
178
177
179
-- create the buffer
178
180
M .bufnr = vim .api .nvim_create_buf (false , true )
@@ -187,8 +189,12 @@ local function open()
187
189
end
188
190
189
191
-- highlight it
190
- for _ , h in ipairs (hl ) do
191
- vim .api .nvim_buf_add_highlight (M .bufnr , - 1 , h [1 ], h [2 ], h [3 ], h [4 ])
192
+ for _ , args in ipairs (hl_range_args ) do
193
+ if vim .fn .has (" nvim-0.11" ) == 1 then
194
+ vim .hl .range (M .bufnr , namespace_help_id , args .higroup , args .start , args .finish , {})
195
+ else
196
+ vim .api .nvim_buf_add_highlight (M .bufnr , - 1 , args .higroup , args .start [1 ], args .start [2 ], args .finish [2 ]) --- @diagnostic disable-line : deprecated
197
+ end
192
198
end
193
199
194
200
-- open a very restricted window
0 commit comments