Skip to content

Commit 033a5d4

Browse files
committed
Add a revert method for custom editors
Fixes microsoft#91700 For microsoft#77131 Having an explicit revert method is a helpful signal that the extension should reload the changes from disk
1 parent adadbe2 commit 033a5d4

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/vs/vscode.proposed.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,14 +1278,26 @@ declare module 'vscode' {
12781278
/**
12791279
* Undo a set of edits.
12801280
*
1281-
* This is triggered when a user undoes an edit or when revert is called on a file.
1281+
* This is triggered when a user undoes an edit.
12821282
*
12831283
* @param edit Array of edits. Sorted from most recent to oldest.
12841284
*
12851285
* @return Thenable signaling that the change has completed.
12861286
*/
12871287
undoEdits(edits: readonly EditType[]): Thenable<void>;
12881288

1289+
/**
1290+
* Revert the file to its last saved state.
1291+
*
1292+
* @param change Added or applied edits.
1293+
*
1294+
* @return Thenable signaling that the change has completed.
1295+
*/
1296+
revert(change: {
1297+
readonly undoneEdits: readonly EditType[];
1298+
readonly appliedEdits: readonly EditType[];
1299+
}): Thenable<void>;
1300+
12891301
/**
12901302
* Back up the resource in its current state.
12911303
*

src/vs/workbench/api/common/extHostWebview.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,23 +303,26 @@ class CustomDocument extends Disposable implements vscode.CustomDocument {
303303
});
304304
}
305305

306-
/** @internal*/ _revert() {
306+
/** @internal*/ async _revert() {
307307
const editing = this.getEditingCapability();
308308
if (this.#currentEditIndex === this.#savePoint) {
309309
return true;
310310
}
311311

312+
313+
let undoneEdits: EditType[] = [];
314+
let appliedEdits: EditType[] = [];
312315
if (this.#currentEditIndex >= this.#savePoint) {
313-
const editsToUndo = this.#edits.slice(this.#savePoint, this.#currentEditIndex);
314-
editing.undoEdits(editsToUndo.reverse());
316+
undoneEdits = this.#edits.slice(this.#savePoint, this.#currentEditIndex).reverse();
315317
} else if (this.#currentEditIndex < this.#savePoint) {
316-
const editsToRedo = this.#edits.slice(this.#currentEditIndex, this.#savePoint);
317-
editing.applyEdits(editsToRedo);
318+
appliedEdits = this.#edits.slice(this.#currentEditIndex, this.#savePoint);
318319
}
319320

320321
this.#currentEditIndex = this.#savePoint;
321322
this.spliceEdits();
322323

324+
await editing.revert({ undoneEdits, appliedEdits });
325+
323326
this.updateState();
324327
return true;
325328
}

0 commit comments

Comments
 (0)