fix cmd+I follow up range bug

This commit is contained in:
Nate Sesti 2024-07-04 11:37:07 -07:00
parent e499ea8bd7
commit 51ac34a3df
2 changed files with 25 additions and 16 deletions

View file

@ -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);
}
}

View file

@ -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) => {