diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 2aeaf676287c616f8495414b3a8e611b6bceb15f..01607b91ed5bf02bc523c8cfa74f042453160416 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -364,7 +364,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } async setModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined, options: EditorOptions | undefined): Promise { - if (this.notebookViewModel === undefined || !this.notebookViewModel.equal(textModel) || this.webview === null) { + if (this.notebookViewModel === undefined || !this.notebookViewModel.equal(textModel)) { this.detachModel(); await this.attachModel(textModel, viewState); } @@ -454,8 +454,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor DOM.toggleClass(this.getDomNode(), 'notebook-editor-editable', !!this.viewModel!.metadata?.editable); } - private createWebview(id: string) { - this.webview = this.instantiationService.createInstance(BackLayerWebView, this, id); + private createWebview(id: string, document: URI) { + this.webview = this.instantiationService.createInstance(BackLayerWebView, this, id, document); this.webview.webview.onDidBlur(() => this.updateEditorFocus()); this.webview.webview.onDidFocus(() => this.updateEditorFocus()); this.localStore.add(this.webview.onMessage(message => { @@ -467,7 +467,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } private async attachModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined) { - this.createWebview(this.getId()); + this.createWebview(this.getId(), textModel.uri); await this.webview!.waitForInitialization(); this.eventDispatcher = new NotebookEventDispatcher(); diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index ac31fb76f8f101d887f39012d7cc58c7cf77cb40..71e20207d278661daa5ba307971f088ed3c2dbcc 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -21,6 +21,8 @@ import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookS import { IWebviewService, WebviewElement } from 'vs/workbench/contrib/webview/browser/webview'; import { asWebviewUri } from 'vs/workbench/contrib/webview/common/webviewUri'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { dirname } from 'vs/base/common/resources'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; export interface IDimensionMessage { __vscode_notebook_message: boolean; @@ -144,10 +146,12 @@ export class BackLayerWebView extends Disposable { constructor( public notebookEditor: INotebookEditor, public id: string, + public documentUri: URI, @IWebviewService readonly webviewService: IWebviewService, @IOpenerService readonly openerService: IOpenerService, @INotebookService private readonly notebookService: INotebookService, @IEnvironmentService private readonly environmentService: IEnvironmentService, + @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, @IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService, ) { super(); @@ -168,9 +172,11 @@ export class BackLayerWebView extends Disposable { resolveFunc = resolve; }); + const baseUrl = asWebviewUri(this.workbenchEnvironmentService, this.id, dirname(documentUri)); + if (!isWeb) { coreDependencies = ``; - const htmlContent = this.generateContent(8, coreDependencies); + const htmlContent = this.generateContent(8, coreDependencies, baseUrl.toString()); this.initialize(htmlContent); resolveFunc!(); } else { @@ -186,18 +192,20 @@ export class BackLayerWebView extends Disposable { ${loaderJs} `; - const htmlContent = this.generateContent(8, coreDependencies); + + const htmlContent = this.generateContent(8, coreDependencies, baseUrl.toString()); this.initialize(htmlContent); resolveFunc!(); }); } } - generateContent(outputNodePadding: number, coreDependencies: string) { + generateContent(outputNodePadding: number, coreDependencies: string, baseUrl: string) { return html` +