diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index b4c379c9227..ee599836346 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1278,7 +1278,7 @@ declare module 'vscode' { /** * Undo a set of edits. * - * This is triggered when a user undoes an edit or when revert is called on a file. + * This is triggered when a user undoes an edit. * * @param edit Array of edits. Sorted from most recent to oldest. * @@ -1286,6 +1286,18 @@ declare module 'vscode' { */ undoEdits(edits: readonly EditType[]): Thenable; + /** + * Revert the file to its last saved state. + * + * @param change Added or applied edits. + * + * @return Thenable signaling that the change has completed. + */ + revert(change: { + readonly undoneEdits: readonly EditType[]; + readonly appliedEdits: readonly EditType[]; + }): Thenable; + /** * Back up the resource in its current state. * diff --git a/src/vs/workbench/api/common/extHostWebview.ts b/src/vs/workbench/api/common/extHostWebview.ts index bdb51f8977c..86588547cd2 100644 --- a/src/vs/workbench/api/common/extHostWebview.ts +++ b/src/vs/workbench/api/common/extHostWebview.ts @@ -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; }