解决webview服务类问题
Some checks failed
Monaco Editor checks / Monaco Editor checks (push) Failing after 39s
Some checks failed
Monaco Editor checks / Monaco Editor checks (push) Failing after 39s
This commit is contained in:
parent
ae05db9b66
commit
73e59d6517
BIN
src.7z
Normal file
BIN
src.7z
Normal file
Binary file not shown.
@ -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<void> {
|
||||
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);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -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('<!DOCTYPE html><html><body></body></html>'); // 清空内容
|
||||
}
|
||||
super.clearInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user