@@ -197,43 +197,50 @@ function Builder:create_combined_group(groups)
197
197
return combined_name
198
198
end
199
199
200
- --- Calculate highlight group for icon and name. A combined highlight group will be created
201
- --- when there is more than one highlight.
200
+ --- Calculate decorated icon and name for a node.
201
+ --- A combined highlight group will be created when there is more than one highlight.
202
202
--- A highlight group is always calculated and upserted for the case of highlights changing.
203
203
--- @private
204
204
--- @param node Node
205
- --- @return string | nil icon_hl_group
206
- --- @return string | nil name_hl_group
207
- function Builder :add_highlights (node )
208
- -- result
209
- local icon_hl_group , name_hl_group
205
+ --- @return HighlightedString icon
206
+ --- @return HighlightedString name
207
+ function Builder :icon_name_decorated (node )
210
208
211
- -- calculate all groups
209
+ -- base case
210
+ local icon = node :highlighted_icon ()
211
+ local name = node :highlighted_name ()
212
+
213
+ -- calculate node icon and all decorated highlight groups
212
214
local icon_groups = {}
213
215
local name_groups = {}
214
- local d , icon , name
216
+ local decorator , hl_icon , hl_name
215
217
for i = # self .decorators , 1 , - 1 do
216
- d = self .decorators [i ]
217
- icon , name = d :highlight_group_icon_name (node )
218
- table.insert (icon_groups , icon )
219
- table.insert (name_groups , name )
218
+ decorator = self .decorators [i ]
219
+
220
+ -- maybe overridde icon
221
+ icon = decorator :icon_node (node ) or icon
222
+
223
+ hl_icon , hl_name = decorator :highlight_group_icon_name (node )
224
+
225
+ table.insert (icon_groups , hl_icon )
226
+ table.insert (name_groups , hl_name )
220
227
end
221
228
222
- -- one or many icon groups
229
+ -- add one or many icon groups
223
230
if # icon_groups > 1 then
224
- icon_hl_group = self :create_combined_group (icon_groups )
231
+ table.insert ( icon . hl , self :create_combined_group (icon_groups ) )
225
232
else
226
- icon_hl_group = icon_groups [1 ]
233
+ table.insert ( icon . hl , icon_groups [1 ])
227
234
end
228
235
229
- -- one or many name groups
236
+ -- add one or many name groups
230
237
if # name_groups > 1 then
231
- name_hl_group = self :create_combined_group (name_groups )
238
+ table.insert ( name . hl , self :create_combined_group (name_groups ) )
232
239
else
233
- name_hl_group = name_groups [1 ]
240
+ table.insert ( name . hl , name_groups [1 ])
234
241
end
235
242
236
- return icon_hl_group , name_hl_group
243
+ return icon , name
237
244
end
238
245
239
246
--- Insert node line into self.lines, calling Builder:build_lines for each directory
@@ -246,13 +253,8 @@ function Builder:build_line(node, idx, num_children)
246
253
local indent_markers = pad .get_indent_markers (self .depth , idx , num_children , node , self .markers )
247
254
local arrows = pad .get_arrows (node )
248
255
249
- -- main components
250
- local icon , name = node :highlighted_icon (), node :highlighted_name ()
251
-
252
- -- highighting
253
- local icon_hl_group , name_hl_group = self :add_highlights (node )
254
- table.insert (icon .hl , icon_hl_group )
255
- table.insert (name .hl , name_hl_group )
256
+ -- decorated node icon and name
257
+ local icon , name = self :icon_name_decorated (node )
256
258
257
259
local line = self :format_line (indent_markers , arrows , icon , name , node )
258
260
table.insert (self .lines , self :unwrap_highlighted_strings (line ))
0 commit comments