Fix #203214. Read code window correctly (#203267)

* Fix #203214. Read code window correctly

* fix diff
This commit is contained in:
Peng Lyu 2024-01-23 17:09:38 -08:00 committed by GitHub
parent 9c95828898
commit 1091f68d83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 12 deletions

View file

@ -484,7 +484,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
}, undefined) as BackLayerWebView<IDiffCellInfo>;
// attach the webview container to the DOM tree first
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._modifiedWebview.element);
this._modifiedWebview.createWebview();
this._modifiedWebview.createWebview(DOM.getActiveWindow());
this._modifiedWebview.element.style.width = `calc(50% - 16px)`;
this._modifiedWebview.element.style.left = `calc(50%)`;
}
@ -501,7 +501,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
}, undefined) as BackLayerWebView<IDiffCellInfo>;
// attach the webview container to the DOM tree first
this._list.rowsContainer.insertAdjacentElement('afterbegin', this._originalWebview.element);
this._originalWebview.createWebview();
this._originalWebview.createWebview(DOM.getActiveWindow());
this._originalWebview.element.style.width = `calc(50% - 16px)`;
this._originalWebview.element.style.left = `16px`;
}

View file

@ -17,11 +17,11 @@ import 'vs/css!./media/notebookCellOutput';
import 'vs/css!./media/notebookEditorStickyScroll';
import 'vs/css!./media/notebookKernelActionViewItem';
import 'vs/css!./media/notebookOutline';
import { PixelRatio } from 'vs/base/browser/browser';
import * as DOM from 'vs/base/browser/dom';
import { IMouseWheelEvent, StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { IListContextMenuEvent } from 'vs/base/browser/ui/list/list';
import { mainWindow } from 'vs/base/browser/window';
import { DeferredPromise, SequencerByKey } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Color, RGBA } from 'vs/base/common/color';
@ -1374,7 +1374,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
throw new Error('Notebook output webview object is not created successfully.');
}
await this._webview.createWebview();
await this._webview.createWebview(this.creationOptions.codeWindow ?? mainWindow);
if (!this._webview.webview) {
throw new Error('Notebook output webview element was not created successfully.');
}

View file

@ -5,6 +5,7 @@
import { getWindow } from 'vs/base/browser/dom';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { CodeWindow } from 'vs/base/browser/window';
import { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
import { coalesce } from 'vs/base/common/arrays';
import { DeferredPromise, runWhenGlobalIdle } from 'vs/base/common/async';
@ -512,10 +513,10 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
return !!this.webview;
}
createWebview(): Promise<void> {
createWebview(codeWindow: CodeWindow): Promise<void> {
const baseUrl = this.asWebviewUri(this.getNotebookBaseUri(), undefined);
const htmlContent = this.generateContent(baseUrl.toString());
return this._initialize(htmlContent);
return this._initialize(htmlContent, codeWindow);
}
private getNotebookBaseUri() {
@ -550,12 +551,12 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
];
}
private _initialize(content: string): Promise<void> {
private _initialize(content: string, codeWindow: CodeWindow): Promise<void> {
if (!getWindow(this.element).document.body.contains(this.element)) {
throw new Error('Element is already detached from the DOM tree');
}
this.webview = this._createInset(this.webviewService, content);
this.webview = this._createInset(this.webviewService, content, codeWindow);
this.webview.mountTo(this.element);
this._register(this.webview);
@ -1122,7 +1123,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
await this.openerService.open(newFileUri);
}
private _createInset(webviewService: IWebviewService, content: string) {
private _createInset(webviewService: IWebviewService, content: string, codeWindow: CodeWindow) {
this.localResourceRootsCache = this._getResourceRootsCache();
const webview = webviewService.createWebviewElement({
origin: BackLayerWebView.getOriginStore(this.storageService).getOrigin(this.notebookViewType, undefined),
@ -1138,7 +1139,8 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
localResourceRoots: this.localResourceRootsCache,
},
extension: undefined,
providedViewType: 'notebook.output'
providedViewType: 'notebook.output',
codeWindow: codeWindow
});
webview.setHtml(content);

View file

@ -5,6 +5,7 @@
import { Dimension } from 'vs/base/browser/dom';
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
import { CodeWindow } from 'vs/base/browser/window';
import { equals } from 'vs/base/common/arrays';
import { Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
@ -77,6 +78,7 @@ export interface WebviewInitInfo {
readonly contentOptions: WebviewContentOptions;
readonly extension: WebviewExtensionDescription | undefined;
readonly codeWindow?: CodeWindow;
}
export const enum WebviewContentPurpose {

View file

@ -180,8 +180,7 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
this._element = this._createElement(initInfo.options, initInfo.contentOptions);
const subscription = this._register(addDisposableListener(getActiveWindow(), 'message', (e: MessageEvent) => {
const subscription = this._register(addDisposableListener(initInfo.codeWindow ?? getActiveWindow(), 'message', (e: MessageEvent) => {
if (!this._encodedWebviewOrigin || e?.data?.target !== this.id) {
return;
}