From 51ac34a3df36582f168a5e06ceea7032081bad80 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 4 Jul 2024 11:37:07 -0700 Subject: [PATCH] fix cmd+I follow up range bug --- .../src/diff/verticalPerLine/handler.ts | 28 +++++++++++-------- .../src/diff/verticalPerLine/manager.ts | 13 +++++---- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/extensions/vscode/src/diff/verticalPerLine/handler.ts b/extensions/vscode/src/diff/verticalPerLine/handler.ts index 8e3d20c8e..feb948b0b 100644 --- a/extensions/vscode/src/diff/verticalPerLine/handler.ts +++ b/extensions/vscode/src/diff/verticalPerLine/handler.ts @@ -210,17 +210,19 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable { } public getLineDeltaBeforeLine(line: number) { - //Returns the number of lines removed from a file when the diff currently active is closed - let totalLineDelta = 0 - for (const range of this.greenDecorationManager.getRanges().sort((a, b) => a.start.line - b.start.line)) { - if (range.start.line > line){ - break + // Returns the number of lines removed from a file when the diff currently active is closed + let totalLineDelta = 0; + for (const range of this.greenDecorationManager + .getRanges() + .sort((a, b) => a.start.line - b.start.line)) { + if (range.start.line > line) { + break; } - totalLineDelta -= range.end.line - range.start.line + 1 + totalLineDelta -= range.end.line - range.start.line + 1; } - return totalLineDelta + return totalLineDelta; } async clear(accept: boolean) { @@ -384,10 +386,10 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable { this.greenDecorationManager.shiftDownAfterLine(startLine, offset); // Shift the codelens objects - this.shiftCodeLensObjects(startLine, offset) + this.shiftCodeLensObjects(startLine, offset); } - private shiftCodeLensObjects(startLine: number, offset: number){ + private shiftCodeLensObjects(startLine: number, offset: number) { // Shift the codelens objects const blocks = this.editorToVerticalDiffCodeLens @@ -404,7 +406,11 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable { this.refreshCodeLens(); } - public updateLineDelta(filepath: string, startLine: number, lineDelta: number) { + public updateLineDelta( + filepath: string, + startLine: number, + lineDelta: number, + ) { // Retrieve the diff blocks for the given file const blocks = this.editorToVerticalDiffCodeLens.get(filepath); if (!blocks) { @@ -416,6 +422,6 @@ export class VerticalPerLineDiffHandler implements vscode.Disposable { this.greenDecorationManager.shiftDownAfterLine(startLine, lineDelta); //update code lens - this.shiftCodeLensObjects(startLine, lineDelta) + this.shiftCodeLensObjects(startLine, lineDelta); } } diff --git a/extensions/vscode/src/diff/verticalPerLine/manager.ts b/extensions/vscode/src/diff/verticalPerLine/manager.ts index 8230c7ffa..d96b78263 100644 --- a/extensions/vscode/src/diff/verticalPerLine/manager.ts +++ b/extensions/vscode/src/diff/verticalPerLine/manager.ts @@ -217,12 +217,15 @@ export class VerticalPerLineDiffManager { } // Clear the previous handler - let effectiveLineDelta = - existingHandler.getLineDeltaBeforeLine(startLine); - existingHandler.clear(false); + // This allows the user to edit above the changed area, + // but extra delta was added for each line generated by Continue + // Before adding this back, we need to distinguish between human and Continue + // let effectiveLineDelta = + // existingHandler.getLineDeltaBeforeLine(startLine); + // startLine += effectiveLineDelta; + // endLine += effectiveLineDelta; - startLine += effectiveLineDelta; - endLine += effectiveLineDelta; + existingHandler.clear(false); } await new Promise((resolve) => {