@@ -323,14 +323,15 @@ To remove existing `label` annotations, use a value of `nothing`.
323323"""
324324function annotate! (s:: AnnotatedString , range:: UnitRange{Int} , @nospecialize (labelval:: Pair{Symbol, <:Any} ))
325325 label, val = labelval
326- indices = searchsorted (s. annotations, (range,), by= first)
327326 if val === nothing
327+ indices = searchsorted (s. annotations, (range,), by= first)
328328 labelindex = filter (i -> first (s. annotations[i][2 ]) === label, indices)
329329 for index in Iterators. reverse (labelindex)
330330 deleteat! (s. annotations, index)
331331 end
332332 else
333- splice! (s. annotations, indices, [(range, Pair {Symbol, Any} (label, val))])
333+ sortedindex = searchsortedlast (s. annotations, (range,), by= first) + 1
334+ insert! (s. annotations, sortedindex, (range, Pair {Symbol, Any} (label, val)))
334335 end
335336 s
336337end
@@ -459,8 +460,8 @@ function _clear_annotations_in_region!(annotations::Vector{Tuple{UnitRange{Int},
459460 end
460461 # Insert any extra entries in the appropriate position
461462 for entry in extras
462- indices = searchsorted (annotations, (first (entry),), by= first)
463- splice ! (annotations, indices, Tuple{UnitRange{Int}, Pair{Symbol, Any}}[ entry] )
463+ sortedindex = searchsortedlast (annotations, (first (entry),), by= first) + 1
464+ insert ! (annotations, sortedindex, entry)
464465 end
465466 end
466467 annotations
@@ -470,8 +471,8 @@ function _insert_annotations!(io::AnnotatedIOBuffer, annotations::Vector{Tuple{U
470471 if ! eof (io)
471472 for (region, annot) in annotations
472473 region = first (region)+ offset: last (region)+ offset
473- indices = searchsorted (io. annotations, (region,), by= first)
474- splice ! (io. annotations, indices, Tuple{UnitRange{Int}, Pair{Symbol, Any}}[ (region, annot)] )
474+ sortedindex = searchsortedlast (io. annotations, (region,), by= first) + 1
475+ insert ! (io. annotations, sortedindex, (region, annot))
475476 end
476477 else
477478 for (region, annot) in annotations
0 commit comments