Skip to content

Commit 1091f68

Browse files
authored
Fix microsoft#203214. Read code window correctly (microsoft#203267)
* Fix microsoft#203214. Read code window correctly * fix diff
1 parent 9c95828 commit 1091f68

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
484484
}, undefined) as BackLayerWebView<IDiffCellInfo>;
485485
// attach the webview container to the DOM tree first
486486
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element);
487-
this._modifiedWebview.createWebview();
487+
this._modifiedWebview.createWebview(DOM.getActiveWindow());
488488
this._modifiedWebview.element.style.width = `calc(50% - 16px)`;
489489
this._modifiedWebview.element.style.left = `calc(50%)`;
490490
}
@@ -501,7 +501,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
501501
}, undefined) as BackLayerWebView<IDiffCellInfo>;
502502
// attach the webview container to the DOM tree first
503503
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element);
504-
this._originalWebview.createWebview();
504+
this._originalWebview.createWebview(DOM.getActiveWindow());
505505
this._originalWebview.element.style.width = `calc(50% - 16px)`;
506506
this._originalWebview.element.style.left = `16px`;
507507
}

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import 'vs/css!./media/notebookCellOutput';
1717
import 'vs/css!./media/notebookEditorStickyScroll';
1818
import 'vs/css!./media/notebookKernelActionViewItem';
1919
import 'vs/css!./media/notebookOutline';
20-
2120
import { PixelRatio } from 'vs/base/browser/browser';
2221
import * as DOM from 'vs/base/browser/dom';
2322
import { IMouseWheelEvent, StandardMouseEvent } from 'vs/base/browser/mouseEvent';
2423
import { IListContextMenuEvent } from 'vs/base/browser/ui/list/list';
24+
import { mainWindow } from 'vs/base/browser/window';
2525
import { DeferredPromise, SequencerByKey } from 'vs/base/common/async';
2626
import { CancellationToken } from 'vs/base/common/cancellation';
2727
import { Color, RGBA } from 'vs/base/common/color';
@@ -1374,7 +1374,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
13741374
throw new Error('Notebook output webview object is not created successfully.');
13751375
}
13761376

1377-
await this._webview.createWebview();
1377+
await this._webview.createWebview(this.creationOptions.codeWindow ?? mainWindow);
13781378
if (!this._webview.webview) {
13791379
throw new Error('Notebook output webview element was not created successfully.');
13801380
}

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { getWindow } from 'vs/base/browser/dom';
77
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
8+
import { CodeWindow } from 'vs/base/browser/window';
89
import { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
910
import { coalesce } from 'vs/base/common/arrays';
1011
import { DeferredPromise, runWhenGlobalIdle } from 'vs/base/common/async';
@@ -512,10 +513,10 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
512513
return !!this.webview;
513514
}
514515

515-
createWebview(): Promise<void> {
516+
createWebview(codeWindow: CodeWindow): Promise<void> {
516517
const baseUrl = this.asWebviewUri(this.getNotebookBaseUri(), undefined);
517518
const htmlContent = this.generateContent(baseUrl.toString());
518-
return this._initialize(htmlContent);
519+
return this._initialize(htmlContent, codeWindow);
519520
}
520521

521522
private getNotebookBaseUri() {
@@ -550,12 +551,12 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
550551
];
551552
}
552553

553-
private _initialize(content: string): Promise<void> {
554+
private _initialize(content: string, codeWindow: CodeWindow): Promise<void> {
554555
if (!getWindow(this.element).document.body.contains(this.element)) {
555556
throw new Error('Element is already detached from the DOM tree');
556557
}
557558

558-
this.webview = this._createInset(this.webviewService, content);
559+
this.webview = this._createInset(this.webviewService, content, codeWindow);
559560
this.webview.mountTo(this.element);
560561
this._register(this.webview);
561562

@@ -1122,7 +1123,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
11221123
await this.openerService.open(newFileUri);
11231124
}
11241125

1125-
private _createInset(webviewService: IWebviewService, content: string) {
1126+
private _createInset(webviewService: IWebviewService, content: string, codeWindow: CodeWindow) {
11261127
this.localResourceRootsCache = this._getResourceRootsCache();
11271128
const webview = webviewService.createWebviewElement({
11281129
origin: BackLayerWebView.getOriginStore(this.storageService).getOrigin(this.notebookViewType, undefined),
@@ -1138,7 +1139,8 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
11381139
localResourceRoots: this.localResourceRootsCache,
11391140
},
11401141
extension: undefined,
1141-
providedViewType: 'notebook.output'
1142+
providedViewType: 'notebook.output',
1143+
codeWindow: codeWindow
11421144
});
11431145

11441146
webview.setHtml(content);

src/vs/workbench/contrib/webview/browser/webview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Dimension } from 'vs/base/browser/dom';
77
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
8+
import { CodeWindow } from 'vs/base/browser/window';
89
import { equals } from 'vs/base/common/arrays';
910
import { Event } from 'vs/base/common/event';
1011
import { IDisposable } from 'vs/base/common/lifecycle';
@@ -77,6 +78,7 @@ export interface WebviewInitInfo {
7778
readonly contentOptions: WebviewContentOptions;
7879

7980
readonly extension: WebviewExtensionDescription | undefined;
81+
readonly codeWindow?: CodeWindow;
8082
}
8183

8284
export const enum WebviewContentPurpose {

src/vs/workbench/contrib/webview/browser/webviewElement.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
180180

181181
this._element = this._createElement(initInfo.options, initInfo.contentOptions);
182182

183-
184-
const subscription = this._register(addDisposableListener(getActiveWindow(), 'message', (e: MessageEvent) => {
183+
const subscription = this._register(addDisposableListener(initInfo.codeWindow ?? getActiveWindow(), 'message', (e: MessageEvent) => {
185184
if (!this._encodedWebviewOrigin || e?.data?.target !== this.id) {
186185
return;
187186
}

0 commit comments

Comments
 (0)