Merge pull request #8489 from continuedev/dallin/fix-reject-all-diffs
fix: instant reject all for VS Code
This commit is contained in:
commit
399d9fea96
1 changed files with 59 additions and 7 deletions
|
|
@ -136,12 +136,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
|
|||
// Accept all: delete all the red ranges and clear green decorations
|
||||
await this.deleteRangeLines(removedRanges.map((r) => r.range));
|
||||
} else {
|
||||
// Reject all: Re-insert red lines, delete green ones
|
||||
for (const r of removedRanges) {
|
||||
await this.deleteRangeLines([r.range]);
|
||||
await this.insertTextAboveLine(r.range.start.line, r.line);
|
||||
}
|
||||
await this.deleteRangeLines(this.addedLineDecorations.ranges);
|
||||
await this.unifiedRejectAll();
|
||||
}
|
||||
|
||||
this.clearDecorations();
|
||||
|
|
@ -604,6 +599,63 @@ export class VerticalDiffHandler implements vscode.Disposable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the first line number that was changed in a diff
|
||||
* Rejects all diffs in a single edit operation.
|
||||
*/
|
||||
private async unifiedRejectAll() {
|
||||
await this.ensureCurrentFileIsFocused();
|
||||
|
||||
const removedRanges = this.removedLineDecorations.ranges;
|
||||
const addedRanges = this.addedLineDecorations.ranges;
|
||||
|
||||
interface LineOperation {
|
||||
type: "removed" | "added";
|
||||
line?: string; // Only for removed lines
|
||||
range: vscode.Range;
|
||||
}
|
||||
|
||||
const operations: LineOperation[] = [];
|
||||
for (const r of removedRanges) {
|
||||
operations.push({
|
||||
type: "removed",
|
||||
line: r.line,
|
||||
range: r.range,
|
||||
});
|
||||
}
|
||||
for (const range of addedRanges) {
|
||||
operations.push({
|
||||
type: "added",
|
||||
range,
|
||||
});
|
||||
}
|
||||
|
||||
operations.sort((a, b) => b.range.start.line - a.range.start.line);
|
||||
|
||||
const document = this.editor.document;
|
||||
const lines = document.getText().split("\n");
|
||||
|
||||
for (const op of operations) {
|
||||
const lineNum = op.range.start.line;
|
||||
|
||||
if (op.type === "removed") {
|
||||
// Replace the placeholder line with the original content
|
||||
lines[lineNum] = op.line!;
|
||||
} else if (op.type === "added") {
|
||||
// Delete the added lines
|
||||
const startLine = op.range.start.line;
|
||||
const endLine = op.range.end.line;
|
||||
const numLinesToDelete = endLine - startLine + 1;
|
||||
lines.splice(startLine, numLinesToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
const finalContent = lines.join("\n");
|
||||
|
||||
await this.editor.edit(
|
||||
(editBuilder) => {
|
||||
const fullRange = new vscode.Range(0, 0, document.lineCount, 0);
|
||||
editBuilder.replace(fullRange, finalContent);
|
||||
},
|
||||
{ undoStopAfter: false, undoStopBefore: false },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue