mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
Add a revert method for custom editors
Fixes #91700 For #77131 Having an explicit revert method is a helpful signal that the extension should reload the changes from disk
This commit is contained in:
@@ -303,23 +303,26 @@ class CustomDocument extends Disposable implements vscode.CustomDocument {
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal*/ _revert() {
|
||||
/** @internal*/ async _revert() {
|
||||
const editing = this.getEditingCapability();
|
||||
if (this.#currentEditIndex === this.#savePoint) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
let undoneEdits: EditType[] = [];
|
||||
let appliedEdits: EditType[] = [];
|
||||
if (this.#currentEditIndex >= this.#savePoint) {
|
||||
const editsToUndo = this.#edits.slice(this.#savePoint, this.#currentEditIndex);
|
||||
editing.undoEdits(editsToUndo.reverse());
|
||||
undoneEdits = this.#edits.slice(this.#savePoint, this.#currentEditIndex).reverse();
|
||||
} else if (this.#currentEditIndex < this.#savePoint) {
|
||||
const editsToRedo = this.#edits.slice(this.#currentEditIndex, this.#savePoint);
|
||||
editing.applyEdits(editsToRedo);
|
||||
appliedEdits = this.#edits.slice(this.#currentEditIndex, this.#savePoint);
|
||||
}
|
||||
|
||||
this.#currentEditIndex = this.#savePoint;
|
||||
this.spliceEdits();
|
||||
|
||||
await editing.revert({ undoneEdits, appliedEdits });
|
||||
|
||||
this.updateState();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user