diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index 99c2aaeff52..e9889040ffc 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -289,7 +289,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma try { await this._proxy.$resolveWebviewEditor( - webviewInput.getResource(), + { resource: webviewInput.getResource(), edits: model.currentEdits }, handle, viewType, webviewInput.getTitle(), @@ -299,6 +299,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma } catch (error) { onUnexpectedError(error); webviewInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType); + return; } } })); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index fd400006266..414ce05d910 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -592,7 +592,7 @@ export interface ExtHostWebviewsShape { $onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Promise; $deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise; - $resolveWebviewEditor(resource: UriComponents, newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise; + $resolveWebviewEditor(input: { resource: UriComponents, edits: readonly any[] }, newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise; $undoEdits(handle: WebviewPanelHandle, edits: readonly any[]): void; $applyEdits(handle: WebviewPanelHandle, edits: readonly any[]): void; diff --git a/src/vs/workbench/api/common/extHostWebview.ts b/src/vs/workbench/api/common/extHostWebview.ts index 68405468573..bbe3fe187d0 100644 --- a/src/vs/workbench/api/common/extHostWebview.ts +++ b/src/vs/workbench/api/common/extHostWebview.ts @@ -248,11 +248,11 @@ export class ExtHostWebviewEditor extends Disposable implements vscode.WebviewPa } } - _undoEdits(edits: string[]): void { + _undoEdits(edits: readonly any[]): void { assertIsDefined(this._capabilities).editingCapability?.undoEdits(edits); } - _redoEdits(edits: string[]): void { + _redoEdits(edits: readonly any[]): void { assertIsDefined(this._capabilities).editingCapability?.applyEdits(edits); } @@ -432,7 +432,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { } async $resolveWebviewEditor( - resource: UriComponents, + input: { resource: UriComponents, edits: readonly any[] }, handle: WebviewPanelHandle, viewType: string, title: string, @@ -448,8 +448,13 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { const webview = new ExtHostWebview(handle, this._proxy, options, this.initData, this.workspace, extension, this._logService); const revivedPanel = new ExtHostWebviewEditor(handle, this._proxy, viewType, title, typeof position === 'number' && position >= 0 ? typeConverters.ViewColumn.to(position) : undefined, options, webview); this._webviewPanels.set(handle, revivedPanel); - const capabilities = await provider.resolveWebviewEditor({ resource: URI.revive(resource) }, revivedPanel); + const capabilities = await provider.resolveWebviewEditor({ resource: URI.revive(input.resource) }, revivedPanel); revivedPanel._setCapabilities(capabilities); + + // TODO: the first set of edits should likely be passed when resolving + if (input.edits.length) { + revivedPanel._redoEdits(input.edits); + } } $undoEdits(handle: WebviewPanelHandle, edits: string[]): void { diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts index a6d5a037799..673d8f3b96d 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts @@ -52,6 +52,10 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput { return this._editorResource; } + public supportsSplitEditor() { + return true; + } + @memoize getName(): string { return basename(this.labelService.getUriLabel(this.getResource())); @@ -142,6 +146,7 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput { public async resolve(): Promise { this._model = await this.customEditorService.models.loadOrCreate(this.getResource(), this.viewType); this._register(this._model.onDidChangeDirty(() => this._onDidChangeDirty.fire())); + this._onDidChangeDirty.fire(); return await super.resolve(); } diff --git a/src/vs/workbench/contrib/customEditor/common/customEditor.ts b/src/vs/workbench/contrib/customEditor/common/customEditor.ts index 087e4e9a17d..9162ab0e3d2 100644 --- a/src/vs/workbench/contrib/customEditor/common/customEditor.ts +++ b/src/vs/workbench/contrib/customEditor/common/customEditor.ts @@ -65,6 +65,8 @@ export interface ICustomEditorModel extends IWorkingCopy { readonly onWillSave: Event; readonly onWillSaveAs: Event; + readonly currentEdits: readonly CustomEditorEdit[]; + undo(): void; redo(): void; revert(options?: IRevertOptions): Promise; diff --git a/src/vs/workbench/contrib/customEditor/common/customEditorModel.ts b/src/vs/workbench/contrib/customEditor/common/customEditorModel.ts index df42f0c3f0c..bbf355c0377 100644 --- a/src/vs/workbench/contrib/customEditor/common/customEditorModel.ts +++ b/src/vs/workbench/contrib/customEditor/common/customEditorModel.ts @@ -53,6 +53,10 @@ export class CustomEditorModel extends Disposable implements ICustomEditorModel protected readonly _onWillSaveAs = this._register(new Emitter()); readonly onWillSaveAs = this._onWillSaveAs.event; + get currentEdits(): readonly CustomEditorEdit[] { + return this._edits.slice(0, Math.max(0, this._currentEditIndex + 1)); + } + public makeEdit(edit: CustomEditorEdit): void { this._edits.splice(this._currentEditIndex + 1, this._edits.length - this._currentEditIndex, edit.data); this._currentEditIndex = this._edits.length - 1;