1
- local appearance = require " nvim-tree.appearance"
2
1
local core = require " nvim-tree.core"
3
2
local live_filter = require " nvim-tree.live-filter"
4
3
local notify = require " nvim-tree.notify"
@@ -46,7 +45,7 @@ local M = {
46
45
--- @field private root_cwd string absolute path
47
46
--- @field private index number
48
47
--- @field private depth number
49
- --- @field private combined_groups string[] combined group names
48
+ --- @field private combined_groups table< string , boolean> combined group names
50
49
--- @field private markers boolean[] indent markers
51
50
local Builder = {}
52
51
@@ -246,22 +245,17 @@ function Builder:build_signs(node)
246
245
end
247
246
end
248
247
249
- --- Combined group name less than the 200 byte limit of highlight group names
250
- --- @private
251
- --- @param groups string[] highlight group names
252
- --- @return string name " NvimTreeCombinedHL" .. sha256
253
- function Builder :combined_group_name (groups )
254
- return string.format (" NvimTreeCombinedHL%s" , vim .fn .sha256 (table.concat (groups )))
255
- end
256
-
257
248
--- Create a highlight group for groups with later groups overriding previous.
249
+ --- Combined group name is less than the 200 byte limit of highlight group names
258
250
--- @private
259
251
--- @param groups string[] highlight group names
252
+ --- @return string group_name " NvimTreeCombinedHL" .. sha256
260
253
function Builder :create_combined_group (groups )
261
- local combined_name = self : combined_group_name ( groups )
254
+ local combined_name = string.format ( " NvimTreeCombinedHL%s " , vim . fn . sha256 ( table.concat ( groups )) )
262
255
263
256
-- only create if necessary
264
- if not vim .tbl_contains (self .combined_groups , combined_name ) then
257
+ if not self .combined_groups [combined_name ] then
258
+ self .combined_groups [combined_name ] = true
265
259
local combined_hl = {}
266
260
267
261
-- build the highlight, overriding values
@@ -270,11 +264,13 @@ function Builder:create_combined_group(groups)
270
264
combined_hl = vim .tbl_extend (" force" , combined_hl , hl )
271
265
end
272
266
273
- -- highlight directly in the namespace
274
- vim .api .nvim_set_hl (appearance . NS_ID , combined_name , combined_hl )
267
+ -- add highlights to the global namespace
268
+ vim .api .nvim_set_hl (0 , combined_name , combined_hl )
275
269
276
270
table.insert (self .combined_groups , combined_name )
277
271
end
272
+
273
+ return combined_name
278
274
end
279
275
280
276
--- Calculate highlight group for icon and name. A combined highlight group will be created
@@ -301,16 +297,14 @@ function Builder:add_highlights(node)
301
297
302
298
-- one or many icon groups
303
299
if # icon_groups > 1 then
304
- icon_hl_group = self :combined_group_name (icon_groups )
305
- self :create_combined_group (icon_groups )
300
+ icon_hl_group = self :create_combined_group (icon_groups )
306
301
else
307
302
icon_hl_group = icon_groups [1 ]
308
303
end
309
304
310
305
-- one or many name groups
311
306
if # name_groups > 1 then
312
- name_hl_group = self :combined_group_name (name_groups )
313
- self :create_combined_group (name_groups )
307
+ name_hl_group = self :create_combined_group (name_groups )
314
308
else
315
309
name_hl_group = name_groups [1 ]
316
310
end
0 commit comments