diff --git a/src.7z b/src.7z new file mode 100644 index 0000000..2cec78c Binary files /dev/null and b/src.7z differ diff --git a/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts b/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts index 32dc9bd..3d43fe1 100644 --- a/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts +++ b/src/vs/workbench/contrib/example/browser/editors/StockDetailsEditor.ts @@ -5,10 +5,10 @@ import { EditorPane } from '../../../../browser/parts/editor/editorPane.js'; import { Dimension } from '../../../../../base/browser/dom.js'; import { StockDetailsInput } from './StockDetailsInput.js'; +import { IWebviewService, IOverlayWebview } from '../../../../contrib/webview/browser/webview.js'; import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js'; import { IThemeService } from '../../../../../platform/theme/common/themeService.js'; import { IStorageService } from '../../../../../platform/storage/common/storage.js'; - import { CancellationToken } from '../../../../../base/common/cancellation.js'; import { IEditorOptions } from '../../../../../platform/editor/common/editor.js'; import { IEditorOpenContext } from '../../../../common/editor.js'; @@ -18,19 +18,20 @@ import * as DOM from '../../../../../base/browser/dom.js'; export class StockDetailsEditor extends EditorPane { static readonly ID = 'workbench.editor.stockDetails'; - private container: HTMLElement | null = null; + private webview: IOverlayWebview | null = null; constructor( group: IEditorGroup, @ITelemetryService telemetryService: ITelemetryService, @IThemeService themeService: IThemeService, - @IStorageService storageService: IStorageService + @IStorageService storageService: IStorageService, + @IWebviewService private readonly webviewService: IWebviewService ) { super(StockDetailsEditor.ID, group, telemetryService, themeService, storageService); } /** - * 创建编辑器容器并初始化界面。 + * 创建编辑器容器并初始化 WebView。 */ protected createEditor(parent: HTMLElement): void { // 使用 WebView 服务创建 IOverlayWebview 实例 @@ -41,38 +42,31 @@ export class StockDetailsEditor extends EditorPane { contentOptions: { allowScripts: true, localResourceRoots: [], // 根据需求设置本地资源根路径 - localResourceRoots: [], // 根据需求设置本地资源根路径 }, extension: undefined, }); // 将 WebView 定位到父元素 if (this.webview) { - // 获取当前激活的窗口 // 获取当前激活的窗口 const targetWindow = DOM.getActiveWindow(); - if (!targetWindow) { console.error('无法获取活动窗口'); return; } - // Claim WebView 所有权,绑定到目标窗口 // Claim WebView 所有权,绑定到目标窗口 this.webview.claim(this, targetWindow as any, undefined); - // 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent` - // 使用 layoutWebviewOverElement 方法,将 WebView 定位到 `parent` this.webview.layoutWebviewOverElement(parent, new Dimension(parent.offsetWidth, parent.offsetHeight)); } - } /** - * 设置编辑器输入。 + * 设置编辑器输入并更新 WebView 内容。 */ override async setInput( input: StockDetailsInput, @@ -82,8 +76,7 @@ export class StockDetailsEditor extends EditorPane { ): Promise { await super.setInput(input, options, context, token); - if (input.resource) { - console.log(`setInput 接收到股票代码: ${input.getCode()}`); + if (this.webview && input.resource) { const stockCode = input.getCode(); if (!stockCode || stockCode.trim() === '') { @@ -169,7 +162,7 @@ export class StockDetailsEditor extends EditorPane { setTimeout(() => { document.getElementById('price').textContent = '价格: ¥' + (Math.random() * 100).toFixed(2); document.getElementById('change').textContent = '涨跌幅: ' + (Math.random() * 10 - 5).toFixed(2) + '%'; - }, 100); + }, 1000); @@ -205,13 +198,10 @@ export class StockDetailsEditor extends EditorPane { if (this.webview && this.webview.container) { const webviewContainer = this.webview.container; - // 设置 WebView 的宽高 - // 设置 WebView 的宽高 webviewContainer.style.width = `${dimension.width}px`; webviewContainer.style.height = `${dimension.height}px`; - // 限制 WebView 到当前编辑器区域 // 限制 WebView 到当前编辑器区域 const clippingContainer = this.getContainer(); if (clippingContainer) { @@ -224,16 +214,10 @@ export class StockDetailsEditor extends EditorPane { * 清空输入内容。 */ override clearInput(): void { - if (this.container) { - this.container.textContent = ''; // 不使用 innerHTML + if (this.webview) { + this.webview.setHtml(''); // 清空内容 } super.clearInput(); } } - - - - - -