@@ -323,14 +323,15 @@ To remove existing `label` annotations, use a value of `nothing`.
323
323
"""
324
324
function annotate! (s:: AnnotatedString , range:: UnitRange{Int} , @nospecialize (labelval:: Pair{Symbol, <:Any} ))
325
325
label, val = labelval
326
- indices = searchsorted (s. annotations, (range,), by= first)
327
326
if val === nothing
327
+ indices = searchsorted (s. annotations, (range,), by= first)
328
328
labelindex = filter (i -> first (s. annotations[i][2 ]) === label, indices)
329
329
for index in Iterators. reverse (labelindex)
330
330
deleteat! (s. annotations, index)
331
331
end
332
332
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)))
334
335
end
335
336
s
336
337
end
@@ -459,8 +460,8 @@ function _clear_annotations_in_region!(annotations::Vector{Tuple{UnitRange{Int},
459
460
end
460
461
# Insert any extra entries in the appropriate position
461
462
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)
464
465
end
465
466
end
466
467
annotations
@@ -470,8 +471,8 @@ function _insert_annotations!(io::AnnotatedIOBuffer, annotations::Vector{Tuple{U
470
471
if ! eof (io)
471
472
for (region, annot) in annotations
472
473
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))
475
476
end
476
477
else
477
478
for (region, annot) in annotations
0 commit comments