diff --git a/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts b/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts index 0456316..1c32fe4 100644 --- a/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts +++ b/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts @@ -13,6 +13,7 @@ import { CancellationToken } from '../../../../../base/common/cancellation.js'; import { IEditorOptions } from '../../../../../platform/editor/common/editor.js'; import { IEditorOpenContext } from '../../../../common/editor.js'; import { IEditorGroup } from '../../../../services/editor/common/editorGroupsService.js'; +import * as DOM from '../../../../../base/browser/dom.js'; export class StockDetailsEditor extends EditorPane { static readonly ID = 'workbench.editor.stockDetails'; @@ -32,16 +33,35 @@ export class StockDetailsEditor extends EditorPane { * 创建编辑器容器并初始化界面。 */ protected createEditor(parent: HTMLElement): void { - this.container = document.createElement('div'); - this.container.className = 'stock-details-editor'; + // 使用 WebView 服务创建 IOverlayWebview 实例 + this.webview = this.webviewService.createWebviewOverlay({ + providedViewType: 'stockDetailsEditor', + title: '股票详情', + options: { retainContextWhenHidden: true }, + contentOptions: { + allowScripts: true, + localResourceRoots: [], // 根据需求设置本地资源根路径 + }, + extension: undefined, + }); - // 添加占位符 - const placeholder = document.createElement('div'); - placeholder.className = 'stock-placeholder'; - placeholder.textContent = '请选择一只股票查看详情'; - this.container.appendChild(placeholder); + // 将 WebView 定位到父元素 + if (this.webview) { + // 获取当前激活的窗口 + const targetWindow = DOM.getActiveWindow(); + + if (!targetWindow) { + console.error('无法获取活动窗口'); + return; + } + + // Claim WebView 所有权,绑定到目标窗口 + this.webview.claim(this, targetWindow as any, undefined); + + // 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent` + this.webview.layoutWebviewOverElement(parent, new Dimension(parent.offsetWidth, parent.offsetHeight)); + } - parent.appendChild(this.container); } /** @@ -59,57 +79,99 @@ export class StockDetailsEditor extends EditorPane { console.log(`setInput 接收到股票代码: ${input.getCode()}`); const stockCode = input.getCode(); + if (!stockCode || stockCode.trim() === '') { this.renderErrorMessage('股票代码为空,请选择有效的股票。'); return; } - this.renderStockDetails(stockCode); - } else { - this.renderErrorMessage('未提供有效的股票代码'); + // 设置 WebView HTML 内容 + const htmlContent = this.generateWebviewContent(stockCode); + this.webview.setHtml(htmlContent); } - } /** - * 根据股票代码加载详情。 + * 生成 WebView 的 HTML 内容。 */ - private renderStockDetails(stockCode: string): void { - if (!this.container) { - return; - } + // private generateWebviewContent(stockCode: string): string { + // return ` + // + // + //
+ // + // + //