114
114
115
115
--- @class HighlightedString
116
116
--- @field str string
117
- --- @field hl string | nil
117
+ --- @field hl string[]
118
118
119
119
--- @param highlighted_strings HighlightedString[]
120
120
--- @return string
@@ -126,7 +126,7 @@ function Builder:_unwrap_highlighted_strings(highlighted_strings)
126
126
local string = " "
127
127
for _ , v in ipairs (highlighted_strings ) do
128
128
if # v .str > 0 then
129
- if v .hl then
129
+ if v .hl and type ( v . hl ) == " table " then
130
130
self :_insert_highlight (v .hl , # string , # string + # v .str )
131
131
end
132
132
string = string .. v .str
@@ -136,7 +136,8 @@ function Builder:_unwrap_highlighted_strings(highlighted_strings)
136
136
end
137
137
138
138
--- @param node table
139
- --- @return HighlightedString icon , HighlightedString name
139
+ --- @return HighlightedString icon
140
+ --- @return HighlightedString name
140
141
function Builder :_build_folder (node )
141
142
local has_children = # node .nodes ~= 0 or node .has_children
142
143
local icon , icon_hl = icons .get_folder_icon (node , has_children )
@@ -166,11 +167,12 @@ function Builder:_build_folder(node)
166
167
foldername_hl = " NvimTreeEmptyFolderName"
167
168
end
168
169
169
- return { str = icon , hl = icon_hl }, { str = foldername , hl = foldername_hl }
170
+ return { str = icon , hl = { icon_hl } } , { str = foldername , hl = { foldername_hl } }
170
171
end
171
172
172
173
--- @param node table
173
- --- @return HighlightedString icon , HighlightedString name
174
+ --- @return HighlightedString icon
175
+ --- @return HighlightedString name
174
176
function Builder :_build_symlink (node )
175
177
local icon = icons .i .symlink
176
178
local arrow = icons .i .symlink_arrow
@@ -180,21 +182,19 @@ function Builder:_build_symlink(node)
180
182
symlink_formatted = symlink_formatted .. arrow .. link_to
181
183
end
182
184
183
- local link_highlight = " NvimTreeSymlink"
184
- local icon_hl = " NvimTreeSymlinkIcon"
185
-
186
- return { str = icon , hl = icon_hl }, { str = symlink_formatted , hl = link_highlight }
185
+ return { str = icon , hl = { " NvimTreeSymlinkIcon" } }, { str = symlink_formatted , hl = { " NvimTreeSymlink" } }
187
186
end
188
187
189
188
--- @param node table
190
189
--- @return HighlightedString icon
191
190
function Builder :_build_file_icon (node )
192
191
local icon , hl_group = icons .get_file_icon (node .name , node .extension )
193
- return { str = icon , hl = hl_group }
192
+ return { str = icon , hl = { hl_group } }
194
193
end
195
194
196
195
--- @param node table
197
- --- @return HighlightedString icon , HighlightedString name
196
+ --- @return HighlightedString icon
197
+ --- @return HighlightedString name
198
198
function Builder :_build_file (node )
199
199
local icon = self :_build_file_icon (node )
200
200
@@ -207,15 +207,15 @@ function Builder:_build_file(node)
207
207
hl = " NvimTreeImageFile"
208
208
end
209
209
210
- return icon , { str = node .name , hl = hl }
210
+ return icon , { str = node .name , hl = { hl } }
211
211
end
212
212
213
213
--- @param node table
214
214
--- @return HighlightedString[] | nil icon
215
215
function Builder :_get_git_icons (node )
216
216
local git_icons = git .get_icons (node )
217
217
if git_icons and # git_icons > 0 and self .git_placement == " signcolumn" then
218
- table.insert (self .signs , { sign = git_icons [1 ].hl , lnum = self .index + 1 , priority = 1 })
218
+ table.insert (self .signs , { sign = git_icons [1 ].hl [ 1 ] , lnum = self .index + 1 , priority = 1 })
219
219
git_icons = nil
220
220
end
221
221
return git_icons
226
226
function Builder :_get_diagnostics_icon (node )
227
227
local diagnostics_icon = diagnostics .get_icon (node )
228
228
if diagnostics_icon and self .diagnostics_placement == " signcolumn" then
229
- table.insert (self .signs , { sign = diagnostics_icon .hl , lnum = self .index + 1 , priority = 2 })
229
+ table.insert (self .signs , { sign = diagnostics_icon .hl [ 1 ] , lnum = self .index + 1 , priority = 2 })
230
230
diagnostics_icon = nil
231
231
end
232
232
return diagnostics_icon
@@ -237,14 +237,15 @@ end
237
237
function Builder :_get_modified_icon (node )
238
238
local modified_icon = modified .get_icon (node )
239
239
if modified_icon and self .modified_placement == " signcolumn" then
240
- table.insert (self .signs , { sign = modified_icon .hl , lnum = self .index + 1 , priority = 3 })
240
+ table.insert (self .signs , { sign = modified_icon .hl [ 1 ] , lnum = self .index + 1 , priority = 3 })
241
241
modified_icon = nil
242
242
end
243
243
return modified_icon
244
244
end
245
245
246
246
--- @param node table
247
- --- @return string icon_highlight , string name_highlight
247
+ --- @return string | nil icon_hl
248
+ --- @return string | nil name_hl
248
249
function Builder :_get_highlight_override (node , unloaded_bufnr )
249
250
-- highlights precedence:
250
251
-- original < git < opened_file < modified
@@ -290,6 +291,20 @@ function Builder:_get_highlight_override(node, unloaded_bufnr)
290
291
return icon_hl , name_hl
291
292
end
292
293
294
+ --- @param node table
295
+ --- @return string[] icon_hl
296
+ --- @return string[] name_hl
297
+ function Builder :_get_highlight_extra (node )
298
+ local icon_hl = {}
299
+ local name_hl = {}
300
+
301
+ -- clipboard
302
+ local clipboard_highlight = require " nvim-tree.actions.fs.copy-paste" .get_highlight (node )
303
+ table.insert (name_hl , clipboard_highlight )
304
+
305
+ return icon_hl , name_hl
306
+ end
307
+
293
308
--- @param indent_markers HighlightedString[]
294
309
--- @param arrows HighlightedString[] | nil
295
310
--- @param icon HighlightedString
@@ -364,12 +379,21 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
364
379
end
365
380
366
381
-- highlight override
367
- local icon_hl , name_hl = self :_get_highlight_override (node , unloaded_bufnr )
368
- if icon_hl then
369
- icon .hl = icon_hl
382
+ local icon_hl_override , name_hl_override = self :_get_highlight_override (node , unloaded_bufnr )
383
+ if icon_hl_override then
384
+ icon .hl = { icon_hl_override }
385
+ end
386
+ if name_hl_override then
387
+ name .hl = { name_hl_override }
388
+ end
389
+
390
+ -- extra highighting
391
+ local icon_hl_extra , name_hl_extra = self :_get_highlight_extra (node )
392
+ for _ , hl in ipairs (icon_hl_extra ) do
393
+ table.insert (icon .hl , hl )
370
394
end
371
- if name_hl then
372
- name .hl = name_hl
395
+ for _ , hl in ipairs ( name_hl_extra ) do
396
+ table.insert ( name .hl , hl )
373
397
end
374
398
375
399
local line = self :_format_line (indent_markers , arrows , icon , name , git_icons , diagnostics_icon , modified_icon )
@@ -429,16 +453,16 @@ function Builder:build_header(show_header)
429
453
if show_header then
430
454
local root_name = format_root_name (self .root_cwd , self .root_folder_label )
431
455
self :_insert_line (root_name )
432
- self :_insert_highlight (" NvimTreeRootFolder" , 0 , string.len (root_name ))
456
+ self :_insert_highlight ({ " NvimTreeRootFolder" } , 0 , string.len (root_name ))
433
457
self .index = 1
434
458
end
435
459
436
460
if self .filter then
437
461
local filter_line = self .filter_prefix .. " /" .. self .filter .. " /"
438
462
self :_insert_line (filter_line )
439
463
local prefix_length = string.len (self .filter_prefix )
440
- self :_insert_highlight (" NvimTreeLiveFilterPrefix" , 0 , prefix_length )
441
- self :_insert_highlight (" NvimTreeLiveFilterValue" , prefix_length , string.len (filter_line ))
464
+ self :_insert_highlight ({ " NvimTreeLiveFilterPrefix" } , 0 , prefix_length )
465
+ self :_insert_highlight ({ " NvimTreeLiveFilterValue" } , prefix_length , string.len (filter_line ))
442
466
self .index = self .index + 1
443
467
end
444
468
0 commit comments