src/vs/editor/common/diff/algorithms/joinSequenceDiffs.ts/joinSequenceDiffs
export function joinSequenceDiffs(sequence1: ISequence, sequence2: ISequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
	const result: SequenceDiff[] = [];
	if (sequenceDiffs.length > 0) {
		result.push(sequenceDiffs[0]);
	}

	for (let i = 1; i < sequenceDiffs.length; i++) {
		const lastResult = result[result.length - 1];
		const cur = sequenceDiffs[i];

		if (cur.seq1Range.isEmpty) {
			let all = true;
			const length = cur.seq1Range.start - lastResult.seq1Range.endExclusive;
			for (let i = 1; i <= length; i++) {
				if (sequence2.getElement(cur.seq2Range.start - i) !== sequence2.getElement(cur.seq2Range.endExclusive - i)) {
					all = false;
					break;
				}
			}

			if (all) {
				// Merge previous and current diff
				result[result.length - 1] = new SequenceDiff(lastResult.seq1Range, new OffsetRange(
					lastResult.seq2Range.start,
					cur.seq2Range.endExclusive - length
				));
				continue;
			}
		}

		result.push(cur);
	}

	return result;
}