@@ -11,6 +11,8 @@ local WIN_HL = table.concat({
1111 " CursorLine:NvimTreeCursorLine" ,
1212}, " ," )
1313
14+ local namespace_help_id = vim .api .nvim_create_namespace (" NvimTreeHelp" )
15+
1416local M = {
1517 config = {},
1618
8284
8385--- Compute all lines for the buffer
8486--- @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
8789--- @return number maximum length of text
8890local function compute (map )
8991 local head_lhs = " nvim-tree mappings"
@@ -130,10 +132,10 @@ local function compute(map)
130132 local width = # lines [1 ]
131133
132134 -- 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 , }, },
137139 }
138140
139141 -- mappings, left padded 1
@@ -145,10 +147,10 @@ local function compute(map)
145147 width = math.max (# line , width )
146148
147149 -- 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 , }, })
149151 end
150152
151- return lines , hl , width
153+ return lines , hl_range_args , width
152154end
153155
154156--- close the window and delete the buffer, if they exist
@@ -172,7 +174,7 @@ local function open()
172174 local map = keymap .get_keymap ()
173175
174176 -- text and highlight
175- local lines , hl , width = compute (map )
177+ local lines , hl_range_args , width = compute (map )
176178
177179 -- create the buffer
178180 M .bufnr = vim .api .nvim_create_buf (false , true )
@@ -187,8 +189,12 @@ local function open()
187189 end
188190
189191 -- 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
192198 end
193199
194200 -- open a very restricted window
0 commit comments