Update custom editor api

For #77131

- Use a class for `CustomDocument` instead of an interface. Extensions can now add their own data to a `CustomDocument` by sublassing

- Renamed `resolveCustomDocument` to `openCustomDocument` and require that extensions return a `CustomDocument`

- Exposed edits on `CustomDocument`

- Made the third parameter of `registerCustomEditorProvider` a generic options bag that takes a `webviewOptions`
This commit is contained in:
Matt Bierner
2020-03-23 13:10:38 -07:00
parent 414fc3c7cd
commit 579dab3196
8 changed files with 223 additions and 198 deletions

View File

@@ -663,13 +663,21 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
}
const undoneEdit = this._edits[this._currentEditIndex];
await this._proxy.$undo(this._realResource, this.viewType, undoneEdit);
await this._proxy.$undo(this._realResource, this.viewType, undoneEdit, this.getEditState());
this.change(() => {
--this._currentEditIndex;
});
}
private getEditState(): extHostProtocol.CustomDocumentEditState {
return {
allEdits: this._edits,
currentIndex: this._currentEditIndex,
saveIndex: this._savePoint,
};
}
private async redo(): Promise<void> {
if (!this._editable) {
return;
@@ -681,7 +689,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
}
const redoneEdit = this._edits[this._currentEditIndex + 1];
await this._proxy.$redo(this._realResource, this.viewType, redoneEdit);
await this._proxy.$redo(this._realResource, this.viewType, redoneEdit, this.getEditState());
this.change(() => {
++this._currentEditIndex;
});
@@ -728,7 +736,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod
editsToRedo = this._edits.slice(this._currentEditIndex, this._savePoint);
}
this._proxy.$revert(this._realResource, this.viewType, { undoneEdits: editsToUndo, redoneEdits: editsToRedo });
this._proxy.$revert(this._realResource, this.viewType, { undoneEdits: editsToUndo, redoneEdits: editsToRedo }, this.getEditState());
this.change(() => {
this._currentEditIndex = this._savePoint;
this.spliceEdits();