Change:
Diffing the files: original: modified: <img width="1127" alt="image" src="https://user-"It would be better to line up things differently and give preference to having lines with smaller indent be boundary lines. fyi
Very nice idea!! Very valuable example. I can implement this in the experimental diffing algorithm, and soon we can discuss to deprecate the smart diffing algorithm ().
Implemented in the experimental diff algorithm (not smart). Let's try to deprecate the smart diff algorithm in favor of the experimental in the next milestones.
Closing, as this is implemented in the experimental diff algorithm, which is now the default. To verify, try it out in the playground:

Discussion:
*/ getBoundaryScore?(length: number): number; } <del> export class SequenceFromIntArray implements ISequence { constructor(private readonly arr: number[]) { } getElement(offset: number): number { return this.arr[offset]; } get length(): number { return this.arr.length; } } </del>

let bestDelta = 0; let bestScore = -1; // find best scored delta <del> for (let delta = -deltaBefore; delta < deltaAfter; delta++) { </del> <ins> for (let delta = -deltaBefore; delta <= deltaAfter; delta++) { </ins> const seq2OffsetStart = diff.seq2Range.start + delta; const seq2OffsetEndExclusive = diff.seq2Range.endExclusive + delta; const seq1Offset = diff.seq1Range.start + delta;

import { CharCode } from 'vs/base/common/charCode'; import { Position } from 'vs/editor/common/core/position'; import { Range } from 'vs/editor/common/core/range'; <del> import { SequenceFromIntArray, OffsetRange, SequenceDiff, ISequence } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; </del> <ins> import { OffsetRange, SequenceDiff, ISequence } from 'vs/editor/common/diff/algorithms/diffAlgorithm'; </ins> import { DynamicProgrammingDiffing } from 'vs/editor/common/diff/algorithms/dynamicProgrammingDiffing'; import { optimizeSequenceDiffs } from 'vs/editor/common/diff/algorithms/joinSequenceDiffs'; import { MyersDiffAlgorithm } from 'vs/editor/common/diff/algorithms/myersDiffAlgorithm';

const srcDocLines = originalLines.map((l) => getOrCreateHash(l.trim())); const tgtDocLines = modifiedLines.map((l) => getOrCreateHash(l.trim())); <del> const sequence1 = new SequenceFromIntArray(srcDocLines); const sequence2 = new SequenceFromIntArray(tgtDocLines); </del> <ins> const sequence1 = new LineSequence(srcDocLines, originalLines); const sequence2 = new LineSequence(tgtDocLines, modifiedLines); </ins> <del> const lineAlignments = (() => { </del> <ins> let lineAlignments = (() => { </ins> if (sequence1.length + sequence2.length < 1500) { // Use the improved algorithm for small files return this.dynamicProgrammingDiffing.compute(

); })(); <ins> lineAlignments = optimizeSequenceDiffs(sequence1, sequence2, lineAlignments); </ins> const alignments: RangeMapping[] = []; const scanForWhitespaceChanges = (equalLinesCount: number) => {

} } <ins> export class LineSequence implements ISequence { constructor( private readonly trimmedHash: number[], private readonly lines: string[] ) { } getElement(offset: number): number { return this.trimmedHash[offset]; } get length(): number { return this.trimmedHash.length; } getBoundaryScore(length: number): number { const indentationBefore = length === 0 ? 0 : getIndentation(this.lines[length - 1]); const indentationAfter = length === this.lines.length ? 0 : getIndentation(this.lines[length]); return 1000 - (indentationBefore + indentationAfter); } } function getIndentation(str: string): number { let i = 0; while (i < str.length && (str.charCodeAt(i) === CharCode.Space || str.charCodeAt(i) === CharCode.Tab)) { i++; } return i; } </ins> class Slice implements ISequence { private readonly elements: Int32Array; private readonly firstCharOnLineOffsets: Int32Array;