@@ -153,7 +153,7 @@ lastindex(s::AnnotatedString) = lastindex(s.string)
153153function getindex (s:: AnnotatedString , i:: Integer )
154154 @boundscheck checkbounds (s, i)
155155 @inbounds if isvalid (s, i)
156- AnnotatedChar (s. string[i], annotations (s, i))
156+ AnnotatedChar (s. string[i], map (last, annotations (s, i) ))
157157 else
158158 string_index_err (s, i)
159159 end
@@ -354,12 +354,16 @@ annotate!(c::AnnotatedChar, @nospecialize(labelval::Pair{Symbol, <:Any})) =
354354 (push! (c. annotations, labelval); c)
355355
356356"""
357- annotations(str::AnnotatedString, [position::Union{Integer, UnitRange}])
358- annotations(str::SubString{AnnotatedString}, [position::Union{Integer, UnitRange}])
357+ annotations(str::Union{AnnotatedString, SubString{AnnotatedString}},
358+ [position::Union{Integer, UnitRange}]) ->
359+ Vector{Tuple{UnitRange{Int}, Pair{Symbol, Any}}}
359360
360361Get all annotations that apply to `str`. Should `position` be provided, only
361362annotations that overlap with `position` will be returned.
362363
364+ Annotations are provided together with the regions they apply to, in the form of
365+ a vector of region–annotation tuples.
366+
363367See also: `annotate!`.
364368"""
365369annotations (s:: AnnotatedString ) = s. annotations
@@ -369,22 +373,22 @@ annotations(s::SubString{<:AnnotatedString}) =
369373
370374function annotations (s:: AnnotatedString , pos:: UnitRange{<:Integer} )
371375 # TODO optimise
372- annots = filter (label -> ! isempty (intersect (pos, first (label))),
373- s. annotations)
374- last .(annots)
376+ filter (label -> ! isempty (intersect (pos, first (label))),
377+ s. annotations)
375378end
376379
377380annotations (s:: AnnotatedString , pos:: Integer ) = annotations (s, pos: pos)
378381
379382annotations (s:: SubString{<:AnnotatedString} , pos:: Integer ) =
380383 annotations (s. string, s. offset + pos)
384+
381385annotations (s:: SubString{<:AnnotatedString} , pos:: UnitRange{<:Integer} ) =
382386 annotations (s. string, first (pos)+ s. offset: last (pos)+ s. offset)
383387
384388"""
385- annotations(chr::AnnotatedChar)
389+ annotations(chr::AnnotatedChar) -> Vector{Pair{Symbol, Any}}
386390
387- Get all annotations of `chr`.
391+ Get all annotations of `chr`, in the form of a vector of annotation pairs .
388392"""
389393annotations (c:: AnnotatedChar ) = c. annotations
390394
0 commit comments