From 107e511b820af6d1f28cacfc7e86a971f90a26b6 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 31 Dec 2023 12:04:51 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20new=20line=20matching=20he?= =?UTF-8?q?uristic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/diff/diffLines.ts | 8 ++++---- core/diff/util.ts | 5 +++++ extensions/vscode/src/diff/verticalPerLine.ts | 6 ------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/diff/diffLines.ts b/core/diff/diffLines.ts index b8d1180b5..f055b2b54 100644 --- a/core/diff/diffLines.ts +++ b/core/diff/diffLines.ts @@ -12,10 +12,10 @@ export async function* streamDiff( let newLineResult = await newLines.next(); while (oldLines.length > 0 && !newLineResult.done) { - let newLine = newLineResult.value; - const [matchIndex, isPerfectMatch, newLineWithCorrectIndentation] = - matchLine(newLine, oldLines); - newLine = newLineWithCorrectIndentation; + const [matchIndex, isPerfectMatch, newLine] = matchLine( + newLineResult.value, + oldLines + ); if (matchIndex < 0) { yield { type: "new", line: newLine }; diff --git a/core/diff/util.ts b/core/diff/util.ts index fa217c718..d02aacee8 100644 --- a/core/diff/util.ts +++ b/core/diff/util.ts @@ -23,6 +23,11 @@ export function matchLine( newLine: string, oldLines: string[] ): [number, boolean, string] { + // Only match empty lines if it's the next one: + if (newLine.trim() === "" && oldLines[0]?.trim() === "") { + return [0, true, newLine.trim()]; + } + for (let i = 0; i < oldLines.length; i++) { if (linesMatchPerfectly(newLine, oldLines[i])) { return [i, true, newLine]; diff --git a/extensions/vscode/src/diff/verticalPerLine.ts b/extensions/vscode/src/diff/verticalPerLine.ts index 6f350a7ca..cceb696aa 100644 --- a/extensions/vscode/src/diff/verticalPerLine.ts +++ b/extensions/vscode/src/diff/verticalPerLine.ts @@ -161,12 +161,6 @@ export class VerticalPerLineDiffHandler { private updateIndexLineDecorations() { // Highlight the line at the currentLineIndex // And lightly highlight all lines between that and endLine - console.log( - this.currentLineIndex, - this.newLinesAdded, - this.endLine, - this.startLine - ); if (this.currentLineIndex - this.newLinesAdded >= this.endLine) { this.editor.setDecorations(indexDecorationType, []); this.editor.setDecorations(belowIndexDecorationType, []);