@@ -4,18 +4,19 @@ local core = require "nvim-tree.core"
4
4
local git = require " nvim-tree.renderer.components.git"
5
5
local pad = require " nvim-tree.renderer.components.padding"
6
6
local icons = require " nvim-tree.renderer.components.icons"
7
- local modified = require " nvim-tree.renderer.components.modified"
8
7
local diagnostics = require " nvim-tree.renderer.components.diagnostics"
9
- local bookmarks = require " nvim-tree.renderer.components.bookmarks"
10
8
11
9
local HL_POSITION = require (" nvim-tree.enum" ).HL_POSITION
10
+ local ICON_PLACEMENT = require (" nvim-tree.enum" ).ICON_PLACEMENT
12
11
12
+ --- @class Builder
13
+ --- @field decorators Decorator[]
13
14
local Builder = {}
14
15
Builder .__index = Builder
15
16
16
17
local DEFAULT_ROOT_FOLDER_LABEL = " :~:s?$?/..?"
17
18
18
- function Builder .new (root_cwd )
19
+ function Builder .new (root_cwd , decorators )
19
20
return setmetatable ({
20
21
index = 0 ,
21
22
depth = 0 ,
@@ -24,6 +25,7 @@ function Builder.new(root_cwd)
24
25
markers = {},
25
26
signs = {},
26
27
root_cwd = root_cwd ,
28
+ decorators = decorators ,
27
29
}, Builder )
28
30
end
29
31
@@ -79,22 +81,6 @@ function Builder:configure_diagnostics_icon_placement(where)
79
81
return self
80
82
end
81
83
82
- function Builder :configure_bookmark_icon_placement (where )
83
- if where ~= " after" and where ~= " before" and where ~= " signcolumn" then
84
- where = " before" -- default before
85
- end
86
- self .bookmarks_placement = where
87
- return self
88
- end
89
-
90
- function Builder :configure_modified_placement (where )
91
- if where ~= " after" and where ~= " before" and where ~= " signcolumn" then
92
- where = " after" -- default after
93
- end
94
- self .modified_placement = where
95
- return self
96
- end
97
-
98
84
function Builder :configure_symlink_destination (show )
99
85
self .symlink_destination = show
100
86
return self
247
233
--- @param node table
248
234
--- @return HighlightedString | nil icon
249
235
function Builder :_get_modified_icon (node )
250
- local modified_icon = modified . get_icon (node )
251
- if modified_icon and self .modified_placement == " signcolumn" then
236
+ local modified_icon = self . decorators . modified : get_icon (node )
237
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . signcolumn then
252
238
table.insert (self .signs , {
253
239
sign = modified_icon .hl [1 ],
254
240
lnum = self .index + 1 ,
262
248
--- @param node table
263
249
--- @return HighlightedString[] | nil icon
264
250
function Builder :_get_bookmark_icon (node )
265
- local bookmark_icon = bookmarks . get_icon (node )
266
- if bookmark_icon and self .bookmarks_placement == " signcolumn" then
251
+ local bookmark_icon = self . decorators . bookmark : get_icon (node )
252
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . signcolumn then
267
253
table.insert (self .signs , {
268
254
sign = bookmark_icon .hl [1 ],
269
255
lnum = self .index + 1 ,
@@ -309,6 +295,23 @@ function Builder:_append_highlight(node, get_hl, icon_hl, name_hl)
309
295
end
310
296
end
311
297
298
+ --- Append optional highlighting to icon or name.
299
+ --- @param node table
300
+ --- @param decorator Decorator
301
+ --- @param icon_hl string[] icons to append to
302
+ --- @param name_hl string[] names to append to
303
+ function Builder :_append_dec_highlight (node , decorator , icon_hl , name_hl )
304
+ local pos , hl = decorator :get_highlight (node )
305
+ if pos ~= HL_POSITION .none and hl then
306
+ if pos == HL_POSITION .all or pos == HL_POSITION .icon then
307
+ table.insert (icon_hl , hl )
308
+ end
309
+ if pos == HL_POSITION .all or pos == HL_POSITION .name then
310
+ table.insert (name_hl , hl )
311
+ end
312
+ end
313
+ end
314
+
312
315
--- @param indent_markers HighlightedString[]
313
316
--- @param arrows HighlightedString[] | nil
314
317
--- @param icon HighlightedString
@@ -341,13 +344,13 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
341
344
if git_icons and self .git_placement == " before" then
342
345
add_to_end (line , git_icons )
343
346
end
344
- if modified_icon and self .modified_placement == " before" then
347
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . before then
345
348
add_to_end (line , { modified_icon })
346
349
end
347
350
if diagnostics_icon and self .diagnostics_placement == " before" then
348
351
add_to_end (line , { diagnostics_icon })
349
352
end
350
- if bookmark_icon and self .bookmarks_placement == " before" then
353
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . before then
351
354
add_to_end (line , { bookmark_icon })
352
355
end
353
356
@@ -356,13 +359,13 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
356
359
if git_icons and self .git_placement == " after" then
357
360
add_to_end (line , git_icons )
358
361
end
359
- if modified_icon and self .modified_placement == " after" then
362
+ if modified_icon and self .decorators . modified . icon_placement == ICON_PLACEMENT . after then
360
363
add_to_end (line , { modified_icon })
361
364
end
362
365
if diagnostics_icon and self .diagnostics_placement == " after" then
363
366
add_to_end (line , { diagnostics_icon })
364
367
end
365
- if bookmark_icon and self .bookmarks_placement == " after" then
368
+ if bookmark_icon and self .decorators . bookmark . icon_placement == ICON_PLACEMENT . after then
366
369
add_to_end (line , { bookmark_icon })
367
370
end
368
371
@@ -405,9 +408,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
405
408
406
409
-- extra highighting
407
410
self :_append_highlight (node , git .get_highlight , icon .hl , name .hl )
408
- -- TODO opened
409
- self :_append_highlight (node , modified .get_highlight , icon .hl , name .hl )
410
- self :_append_highlight (node , bookmarks .get_highlight , icon .hl , name .hl )
411
+ self :_append_dec_highlight (node , self .decorators .modified , icon .hl , name .hl )
412
+ self :_append_dec_highlight (node , self .decorators .bookmark , icon .hl , name .hl )
411
413
self :_append_highlight (node , diagnostics .get_highlight , icon .hl , name .hl )
412
414
self :_append_highlight (node , copy_paste .get_highlight , icon .hl , name .hl )
413
415
0 commit comments