Skip to content

Commit 220d833

Browse files
committed
Further refactors for better annotation handling
Since the change in the tweaks lined up for base, we need to adjust how annotations are handled in styledmarkup.jl.
1 parent 5cd1a1a commit 220d833

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/styledmarkup.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module StyledMarkup
77

8-
using Base: AnnotatedString, annotatedstring
8+
using Base: AnnotatedString, annotations, annotatedstring
99
using ..StyledStrings: Face, SimpleColor
1010

1111
export @styled_str, styled
@@ -97,7 +97,7 @@ function addpart!(state::State, stop::Int)
9797
range = (start - state.point[]):(stop - state.point[] + state.offset[] + 1)
9898
push!(styles, tupl(range, annot))
9999
end
100-
sort!(state.pending_styles, by = (r -> (first(r), -last(r))) first) # see `Base._annot_sortkey`
100+
sort!(state.pending_styles, by = (r -> (first(r), -last(r))) first) # Prioritise the most specific styles
101101
for (range, annot) in state.pending_styles
102102
if !isempty(range)
103103
push!(styles, tupl(range .- state.point[], annot))
@@ -135,11 +135,15 @@ function addpart!(state::State, start::Int, expr, stop::Int)
135135
else
136136
push!(state.parts,
137137
:(let $str = string($expr)
138-
if isempty($str)
139-
""
138+
$len = ncodeunits($str) # Used in `annots`.
139+
if $str isa AnnotatedString && !isempty($str)
140+
AnnotatedString(String($str), vcat($annots, annotations($str)))
140141
else
141-
$len = ncodeunits($str)
142-
AnnotatedString($str, $annots)
142+
if isempty($str)
143+
""
144+
else
145+
AnnotatedString($str, $annots)
146+
end
143147
end
144148
end))
145149
end

0 commit comments

Comments
 (0)