Working on sharing models for same custom editor

This commit is contained in:
Matt Bierner
2019-11-23 15:00:16 -08:00
parent b52f1c7dae
commit f3d70dbf92
5 changed files with 22 additions and 16 deletions

View File

@@ -273,8 +273,13 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
const model = await this._customEditorService.models.loadOrCreate(webviewInput.getResource(), webviewInput.viewType);
model.onUndo(edits => { this._proxy.$undoEdits(handle, edits); });
model.onRedo(edits => { this._proxy.$redoEdits(handle, edits); });
model.onUndo(edits => { this._proxy.$undoEdits(handle, edits.map(x => x.data)); });
model.onApplyEdit(edits => {
const editsToApply = edits.filter(x => x.source !== webviewInput).map(x => x.data);
if (editsToApply.length) {
this._proxy.$applyEdits(handle, editsToApply);
}
});
model.onWillSave(e => { e.waitUntil(this._proxy.$onSave(handle)); });
model.onWillSaveAs(e => { e.waitUntil(this._proxy.$onSaveAs(handle, e.resource.toJSON(), e.targetResource.toJSON())); });
@@ -309,7 +314,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
this._editorProviders.delete(viewType);
}
public $onEdit(handle: extHostProtocol.WebviewPanelHandle, editData: string): void {
public $onEdit(handle: extHostProtocol.WebviewPanelHandle, editData: any): void {
const webview = this.getWebviewInput(handle);
if (!(webview instanceof CustomFileEditorInput)) {
throw new Error('Webview is not a webview editor');
@@ -320,7 +325,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
throw new Error('Could not find model for webview editor');
}
model.makeEdit(editData);
model.makeEdit({ source: webview, data: editData });
}
private hookupWebviewEventDelegate(handle: extHostProtocol.WebviewPanelHandle, input: WebviewInput) {