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:
Matt Bierner
2020-03-09 15:46:55 -07:00
parent adadbe271c
commit 033a5d476f
2 changed files with 21 additions and 6 deletions

View File

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