From cf086f01bd3efe96036eb4d0af8103afe4883f68 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 4 Mar 2020 13:36:22 -0800 Subject: [PATCH] Don't send custom editor edit events to extension host for non-editable custom editors --- .../api/browser/mainThreadWebview.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index a3180be6253..858b1ac21d4 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -604,18 +604,27 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod } public async revert(_options?: IRevertOptions) { - this._proxy.$revert(this.resource, this.viewType); + if (this._editable) { + this._proxy.$revert(this.resource, this.viewType); + } } public undo() { - this._proxy.$undo(this.resource, this.viewType); + if (this._editable) { + this._proxy.$undo(this.resource, this.viewType); + } } public redo() { - this._proxy.$redo(this.resource, this.viewType); + if (this._editable) { + this._proxy.$redo(this.resource, this.viewType); + } } public async save(_options?: ISaveOptions): Promise { + if (!this._editable) { + return false; + } await this._proxy.$onSave(this.resource, this.viewType); this.setDirty(false); return true; @@ -634,6 +643,16 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod } public async backup(): Promise { + const backupData: IWorkingCopyBackup = { + meta: { + viewType: this.viewType, + } + }; + + if (!this._editable) { + return backupData; + } + if (this._hotExitState.type === HotExitState.Type.Pending) { this._hotExitState.operation.cancel(); } @@ -657,11 +676,7 @@ class MainThreadCustomEditorModel extends Disposable implements ICustomEditorMod } if (this._hotExitState === HotExitState.Allowed) { - return { - meta: { - viewType: this.viewType, - } - }; + return backupData; } throw new Error('Cannot back up in this state');