@@ -254,21 +254,26 @@ end
254
254
local merge_handlers = {
255
255
winhl = function (highlights , opts )
256
256
Util .each (highlights , function (hl_group , hl_val )
257
+ -- if a group is already applied, then we won't overwrite it
258
+ -- meaning that it had a higher priority
257
259
if M .snapshot .winhl [hl_group ] then
258
260
return
259
261
end
260
262
261
- local key = opts .preset_name .. opts . scope .. hl_group
263
+ local key = opts .scope .. hl_group
262
264
local cached_hl = M .cache .transformed_winhl [key ]
263
265
264
266
if not cached_hl then
265
267
local rhs = Util .transform_winhl (hl_group , hl_val , opts .scope )
266
268
-- collecting all transformed highlights so that we can clear them
267
269
-- if the "ReactiveDisable" autocmd is fired
268
270
M .cache .applied_hl [rhs ] = true
269
- -- since we don't want to transform a highlight group over and over again,
271
+ -- since we don't want to transform a highlight group and set a highlight value over and over again,
270
272
-- it's better to cache it once and then extract from the cache
271
- M .cache .transformed_winhl [key ] = rhs
273
+ -- but we won't cache it if this highlight is dynamic
274
+ if not opts .nocache then
275
+ M .cache .transformed_winhl [key ] = rhs
276
+ end
272
277
273
278
M .snapshot .winhl [hl_group ] = rhs
274
279
else
@@ -303,7 +308,17 @@ function M:form_snapshot(preset_name, highlights, scope, constraints)
303
308
return
304
309
end
305
310
306
- merge_handlers [value ](highlights [value ], opts )
311
+ local highlight_values = highlights [value ]
312
+
313
+ -- highlights can be passed as a funtion and thus be dynamic
314
+ -- in that case we won't cache their values in the `winhl` option
315
+ -- because they can always be different
316
+ if type (highlights [value ]) == ' function' then
317
+ opts .nocache = true
318
+ highlight_values = highlights [value ]()
319
+ end
320
+
321
+ merge_handlers [value ](highlight_values , opts )
307
322
end )
308
323
end
309
324
0 commit comments