@@ -88,12 +88,12 @@ function addpart!(state::State, stop::Int)
8888 styles = sty_type[]
8989 relevant_styles = Iterators. filter (
9090 (_, start, _):: Tuple -> start <= stop + state. offset[] + 1 ,
91- Iterators. flatten (state. active_styles))
91+ Iterators. flatten (map (reverse, state. active_styles) ))
9292 for (_, start, annot) in relevant_styles
9393 range = (start - state. point[]): (stop - state. point[] + state. offset[] + 1 )
9494 push! (styles, tupl (range, annot))
9595 end
96- sort! (state. pending_styles, by = first)
96+ sort! (state. pending_styles, by = (r -> ( first (r), - last (r))) ∘ first) # see `Base._annot_sortkey`
9797 for (range, annot) in state. pending_styles
9898 if ! isempty (range)
9999 push! (styles, tupl (range .- state. point[], annot))
@@ -122,7 +122,10 @@ function addpart!(state::State, start::Int, expr, stop::Int)
122122 len = gensym (" len" )
123123 annots = Expr (:vect , [
124124 Expr (:tuple , Expr (:call , UnitRange, 1 , len), annot)
125- for annot in last .(Iterators. flatten (state. active_styles))]. .. )
125+ for annot in
126+ map (last,
127+ (Iterators. flatten (
128+ map (reverse, state. active_styles))))]. .. )
126129 if isempty (annots. args)
127130 push! (state. parts, :(AnnotatedString (string ($ expr))))
128131 else
@@ -195,7 +198,7 @@ function begin_style!(state::State, i::Int, char::Char)
195198 hasvalue = false
196199 newstyles = Vector{Tuple{Int, Int, Union{Symbol, Expr, Pair{Symbol, Any}}}}()
197200 while read_annotation! (state, i, char, newstyles) end
198- push! (state. active_styles, newstyles)
201+ push! (state. active_styles, reverse! ( newstyles) )
199202 # Adjust bytes/offset based on how much the index
200203 # has been incremented in the processing of the
201204 # style declaration(s).
209212function end_style! (state:: State , i:: Int , char:: Char )
210213 # Close off most recent active style
211214 for (_, start, annot) in pop! (state. active_styles)
212- push ! (state. pending_styles, (start: i+ state. offset[], annot))
215+ pushfirst ! (state. pending_styles, (start: i+ state. offset[], annot))
213216 end
214217 deleteat! (state. bytes, i + state. offset[])
215218 state. offset[] -= ncodeunits (' }' )
0 commit comments