265
266
addRange(range: LineRange): void {
268
return;
269
}
271
>
// Idea: Find joinRange such that:
272
>
// replaceRange = _normalizedRanges.replaceRange(joinRange, range.joinAll(joinRange.map(idx => this._normalizedRanges[idx])))
273
>
274
>
// idx of first element that touches range or that is after range
275
>
const joinRangeStartIdx = findFirstIdxMonotonousOrArrLen(this._normalizedRanges, r => r.endLineNumberExclusive >= range.startLineNumber);
276
>
// idx of element after { last element that touches range or that is before range }
277
>
const joinRangeEndIdxExclusive = findLastIdxMonotonous(this._normalizedRanges, r => r.startLineNumber <= range.endLineNumberExclusive) + 1;
278
>
279
>
if (joinRangeStartIdx === joinRangeEndIdxExclusive) {
280
>
// If there is no element that touches range, then joinRangeStartIdx === joinRangeEndIdxExclusive and that value is the index of the element after range
281
>
this._normalizedRanges.splice(joinRangeStartIdx, 0, range);
282
>
} else if (joinRangeStartIdx === joinRangeEndIdxExclusive - 1) {
283
// Else, there is an element that touches range and in this case it is both the first and last element. Thus we can replace it
284
const joinRange = this._normalizedRanges[joinRangeStartIdx];