174
break;
175
}
177
>
intersecting.push(annotation);
178
>
}
179
180
for (let i = intersecting.length - 1; i >= 0; i--) {
182
>
let r = annotation.range;
183
>
184
>
// Inserted text will extend the first intersecting annotation, if the edit truly overlaps it
185
>
const shouldExtend = i === 0 && (e.replaceRange.endExclusive > r.start) && (e.replaceRange.start < r.endExclusive);
186
>
// Annotation shrinks by the overlap then grows with the new text length
187
>
const overlap = r.intersect(e.replaceRange)!.length;
188
>
r = r.deltaEnd(-overlap + (shouldExtend ? e.newText.length : 0));
189
>
190
>
// If the annotation starts after the edit start, shift left to the edit start position
191
>
const rangeAheadOfReplaceRange = r.start - e.replaceRange.start;
192
>
if (rangeAheadOfReplaceRange > 0) {
193
r = r.delta(-rangeAheadOfReplaceRange);
194
}
196
>
// If annotation shouldn't be extended AND it is after or on edit start, move it after the newly inserted text
197
>
if (!shouldExtend && rangeAheadOfReplaceRange >= 0) {
198
r = r.delta(e.newText.length);
199
}
201
>
// We already took our offset into account.
202
>
// Because we add r back to the queue (which then adds offset again),
203
>
// we have to remove it here so as to not double count it.
204
>
r = r.delta(-(e.newText.length - e.replaceRange.length));
205
>
206
>
annotations.unshift({ annotation: annotation.annotation, range: r });
207
>
}
208
209
offset += e.newText.length - e.replaceRange.length;