From 71685897a87ceff868a375ff60841a63dce9535a Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 1 May 2025 21:37:52 -0700 Subject: [PATCH] myers cleanup --- .../vscode/src/diff/vertical/decorations.ts | 13 ++++++------- extensions/vscode/src/diff/vertical/handler.ts | 17 +++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/extensions/vscode/src/diff/vertical/decorations.ts b/extensions/vscode/src/diff/vertical/decorations.ts index 02f5daca4..2b3b15cca 100644 --- a/extensions/vscode/src/diff/vertical/decorations.ts +++ b/extensions/vscode/src/diff/vertical/decorations.ts @@ -176,16 +176,15 @@ export class RemovedLineDecorationManager { deleteRangesStartingAt(line: number) { for (let i = 0; i < this.ranges.length; i++) { if (this.ranges[i].range.start.line === line) { - this.ranges[i].decoration.dispose(); - let count = 1; + let sequential = 0; while ( - i + count < this.ranges.length && - this.ranges[i + count].range.start.line === line + count + i + sequential < this.ranges.length && + this.ranges[i + sequential].range.start.line === line + sequential ) { - count++; - this.ranges[i + count].decoration.dispose(); + this.ranges[i + sequential].decoration.dispose(); + sequential++; } - return this.ranges.splice(i, count); + return this.ranges.splice(i, sequential); } } } diff --git a/extensions/vscode/src/diff/vertical/handler.ts b/extensions/vscode/src/diff/vertical/handler.ts index 4f1635926..5ba06f014 100644 --- a/extensions/vscode/src/diff/vertical/handler.ts +++ b/extensions/vscode/src/diff/vertical/handler.ts @@ -454,11 +454,11 @@ export class VerticalDiffHandler implements vscode.Disposable { return; } - //update decorations + // Update decorations this.removedLineDecorations.shiftDownAfterLine(startLine, lineDelta); this.addedLineDecorations.shiftDownAfterLine(startLine, lineDelta); - //update code lens + // Update code lens this.shiftCodeLensObjects(startLine, lineDelta); } @@ -504,7 +504,6 @@ export class VerticalDiffHandler implements vscode.Disposable { // newline separated, because myersDiff() would consider // ["A"] => "A" and ["A", ""] => "A\n" to be the same single line. // "A\n" and "A\n\n" are unambiguous. - // const oldFileContent = diffLines .filter((line) => line.type === "same" || line.type === "old") @@ -517,13 +516,15 @@ export class VerticalDiffHandler implements vscode.Disposable { .map((line) => line.line) .join("\n") + "\n"; - const diffs = myersDiff(oldFileContent, newFileContent); + const myersDiffs = myersDiff(oldFileContent, newFileContent); - const myersDiffLines = diffs.map((diff) => diff.line).join("\n"); + const replaceContent = myersDiffs + .map((diff) => (diff.type === "old" ? "" : diff.line)) + .join("\n"); // Then, we insert our diff lines await this.editor.edit((editBuilder) => { - editBuilder.replace(this.range, myersDiffLines), + editBuilder.replace(this.range, replaceContent), { undoStopAfter: false, undoStopBefore: false, @@ -536,7 +537,7 @@ export class VerticalDiffHandler implements vscode.Disposable { const codeLensBlocks: VerticalDiffCodeLens[] = []; - diffs.forEach((diff, index) => { + myersDiffs.forEach((diff, index) => { if (diff.type === "old") { this.removedLineDecorations.addLine(this.startLine + index, diff.line); numRed++; @@ -558,7 +559,7 @@ export class VerticalDiffHandler implements vscode.Disposable { codeLensBlocks.push({ numGreen, numRed, - start: this.startLine + diffs.length - numRed - numGreen, + start: this.startLine + myersDiffs.length - numRed - numGreen, }); }