Skip to content

Commit b35aa43

Browse files
committed
Record modifications made to current faces
This will make it easier to reapply modifications after recolouring.
1 parent 2fd15da commit b35aa43

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/faces.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ const FACES = let default = Dict{Symbol, Face}(
405405
:bright_white => (r = 0xf6, g = 0xf5, b = 0xf4))
406406
(; default, basecolors,
407407
current = ScopedValue(copy(default)),
408+
modifications = ScopedValue(Dict{Symbol, Face}()),
408409
lock = ReentrantLock())
409410
end
410411

@@ -451,6 +452,7 @@ function resetfaces!()
451452
for (key, val) in FACES.default
452453
current[key] = val
453454
end
455+
empty!(FACES.modifications[])
454456
current
455457
end
456458
end
@@ -467,6 +469,7 @@ it is deleted, a warning message is printed, and `nothing` returned.
467469
function resetfaces!(name::Symbol)
468470
@lock FACES.lock if !haskey(FACES.current[], name)
469471
elseif haskey(FACES.default, name)
472+
delete!(FACES.modifications[], name)
470473
FACES.current[][name] = copy(FACES.default[name])
471474
else # This shouldn't happen
472475
delete!(FACES.current[], name)
@@ -656,9 +659,16 @@ Face (sample)
656659
```
657660
"""
658661
function loadface!((name, update)::Pair{Symbol, Face})
659-
@lock FACES.lock if haskey(FACES.current[], name)
660-
FACES.current[][name] = merge(FACES.current[][name], update)
661-
else
662+
@lock FACES.lock begin
663+
mface = get(FACES.modifications[], name, nothing)
664+
if !isnothing(mface)
665+
update = merge(mface, update)
666+
end
667+
FACES.modifications[][name] = update
668+
cface = get(FACES.current[], name, nothing)
669+
if !isnothing(cface)
670+
update = merge(cface, update)
671+
end
662672
FACES.current[][name] = update
663673
end
664674
end

0 commit comments

Comments
 (0)