Skip to content

Commit 49b9d07

Browse files
committed
Introduce face copy method
This is to avoid using deepcopy on faces, as that recursively calls deepcopy on all of its fields, which according to Jamerson can be a little risky once symbols start being deepcopied.
1 parent ac47208 commit 49b9d07

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/faces.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ Base.:(==)(a::Face, b::Face) =
170170
getfield.(Ref(a), fieldnames(Face)) ==
171171
getfield.(Ref(b), fieldnames(Face))
172172

173+
Base.copy(f::Face) =
174+
Face(f.font, f.height, f.weight, f.slant,
175+
f.foreground, f.background, f.underline
176+
f.strikethrough, f.inverse, copy(f.inherit))
177+
173178
function show(io::IO, ::MIME"text/plain", color::SimpleColor)
174179
skiptype = get(io, :typeinfo, nothing) === SimpleColor
175180
skiptype || show(io, SimpleColor)
@@ -388,9 +393,9 @@ function addface!((name, default)::Pair{Symbol, Face})
388393
@lock FACES.lock if !haskey(FACES.default, name)
389394
FACES.default[name] = default
390395
FACES.current[][name] = if haskey(FACES.current[], name)
391-
merge(deepcopy(default), FACES.current[][name])
396+
merge(copy(default), FACES.current[][name])
392397
else
393-
deepcopy(default)
398+
copy(default)
394399
end
395400
end
396401
end
@@ -423,7 +428,7 @@ it is deleted, a warning message is printed, and `nothing` returned.
423428
function resetfaces!(name::Symbol)
424429
@lock FACES.lock if !haskey(FACES.current[], name)
425430
elseif haskey(FACES.default, name)
426-
FACES.current[][name] = deepcopy(FACES.default[name])
431+
FACES.current[][name] = copy(FACES.default[name])
427432
else # This shouldn't happen
428433
delete!(FACES.current[], name)
429434
@warn """The face $name was reset, but it had no default value, and so has been deleted instead!,

0 commit comments

Comments
 (0)