提交 ec8016f7 编写于 作者: M Matt Bierner

Cache webview view title across reloads

Fixes #105867
上级 cf38af84
...@@ -78,7 +78,7 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc ...@@ -78,7 +78,7 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc
}); });
try { try {
await this._proxy.$resolveWebviewView(handle, viewType, state, cancellation); await this._proxy.$resolveWebviewView(handle, viewType, webviewView.title, state, cancellation);
} catch (error) { } catch (error) {
onUnexpectedError(error); onUnexpectedError(error);
webviewView.webview.html = this.mainThreadWebviews.getWebviewResolvedFailedContent(viewType); webviewView.webview.html = this.mainThreadWebviews.getWebviewResolvedFailedContent(viewType);
......
...@@ -686,7 +686,7 @@ export interface ExtHostCustomEditorsShape { ...@@ -686,7 +686,7 @@ export interface ExtHostCustomEditorsShape {
} }
export interface ExtHostWebviewViewsShape { export interface ExtHostWebviewViewsShape {
$resolveWebviewView(webviewHandle: WebviewHandle, viewType: string, state: any, cancellation: CancellationToken): Promise<void>; $resolveWebviewView(webviewHandle: WebviewHandle, viewType: string, title: string | undefined, state: any, cancellation: CancellationToken): Promise<void>;
$onDidChangeWebviewViewVisibility(webviewHandle: WebviewHandle, visible: boolean): void; $onDidChangeWebviewViewVisibility(webviewHandle: WebviewHandle, visible: boolean): void;
......
...@@ -29,12 +29,14 @@ class ExtHostWebviewView extends Disposable implements vscode.WebviewView { ...@@ -29,12 +29,14 @@ class ExtHostWebviewView extends Disposable implements vscode.WebviewView {
handle: extHostProtocol.WebviewHandle, handle: extHostProtocol.WebviewHandle,
proxy: extHostProtocol.MainThreadWebviewViewsShape, proxy: extHostProtocol.MainThreadWebviewViewsShape,
viewType: string, viewType: string,
title: string | undefined,
webview: ExtHostWebview, webview: ExtHostWebview,
isVisible: boolean, isVisible: boolean,
) { ) {
super(); super();
this.#viewType = viewType; this.#viewType = viewType;
this.#title = title;
this.#handle = handle; this.#handle = handle;
this.#proxy = proxy; this.#proxy = proxy;
this.#webview = webview; this.#webview = webview;
...@@ -153,6 +155,7 @@ export class ExtHostWebviewViews implements extHostProtocol.ExtHostWebviewViewsS ...@@ -153,6 +155,7 @@ export class ExtHostWebviewViews implements extHostProtocol.ExtHostWebviewViewsS
async $resolveWebviewView( async $resolveWebviewView(
webviewHandle: string, webviewHandle: string,
viewType: string, viewType: string,
title: string | undefined,
state: any, state: any,
cancellation: CancellationToken, cancellation: CancellationToken,
): Promise<void> { ): Promise<void> {
...@@ -164,7 +167,7 @@ export class ExtHostWebviewViews implements extHostProtocol.ExtHostWebviewViewsS ...@@ -164,7 +167,7 @@ export class ExtHostWebviewViews implements extHostProtocol.ExtHostWebviewViewsS
const { provider, extension } = entry; const { provider, extension } = entry;
const webview = this._extHostWebview.createNewWebview(webviewHandle, { /* todo */ }, extension); const webview = this._extHostWebview.createNewWebview(webviewHandle, { /* todo */ }, extension);
const revivedView = new ExtHostWebviewView(webviewHandle, this._proxy, viewType, webview, true); const revivedView = new ExtHostWebviewView(webviewHandle, this._proxy, viewType, title, webview, true);
this._webviewViews.set(webviewHandle, revivedView); this._webviewViews.set(webviewHandle, revivedView);
......
...@@ -28,7 +28,10 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten ...@@ -28,7 +28,10 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
declare const ResizeObserver: any; declare const ResizeObserver: any;
const webviewStateKey = 'webviewState'; const storageKeys = {
webviewState: 'webviewState',
title: 'title'
} as const;
export class WebviewViewPane extends ViewPane { export class WebviewViewPane extends ViewPane {
...@@ -38,6 +41,9 @@ export class WebviewViewPane extends ViewPane { ...@@ -38,6 +41,9 @@ export class WebviewViewPane extends ViewPane {
private _container?: HTMLElement; private _container?: HTMLElement;
private _resizeObserver?: any; private _resizeObserver?: any;
private readonly defaultTitle: string;
private setTitle: string | undefined;
private readonly memento: Memento; private readonly memento: Memento;
private readonly viewState: MementoObject; private readonly viewState: MementoObject;
...@@ -60,10 +66,16 @@ export class WebviewViewPane extends ViewPane { ...@@ -60,10 +66,16 @@ export class WebviewViewPane extends ViewPane {
@IViewsService private readonly viewService: IViewsService, @IViewsService private readonly viewService: IViewsService,
) { ) {
super({ ...options, titleMenuId: MenuId.ViewTitle }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService); super({ ...options, titleMenuId: MenuId.ViewTitle }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
this.defaultTitle = this.title;
this.memento = new Memento(`webviewView.${this.id}`, storageService); this.memento = new Memento(`webviewView.${this.id}`, storageService);
this.viewState = this.memento.getMemento(StorageScope.WORKSPACE); this.viewState = this.memento.getMemento(StorageScope.WORKSPACE);
const storedTitle = this.viewState[storageKeys.title];
if (typeof storedTitle === 'string') {
this.updateTitle(storedTitle);
}
this._register(this.onDidChangeBodyVisibility(() => this.updateTreeVisibility())); this._register(this.onDidChangeBodyVisibility(() => this.updateTreeVisibility()));
this.updateTreeVisibility(); this.updateTreeVisibility();
} }
...@@ -108,8 +120,9 @@ export class WebviewViewPane extends ViewPane { ...@@ -108,8 +120,9 @@ export class WebviewViewPane extends ViewPane {
public saveState() { public saveState() {
if (this._webview) { if (this._webview) {
this.viewState[webviewStateKey] = this._webview.state; this.viewState[storageKeys.webviewState] = this._webview.state;
} }
this.viewState[storageKeys.title] = this.setTitle;
this.memento.saveMemento(); this.memento.saveMemento();
super.saveState(); super.saveState();
...@@ -142,7 +155,7 @@ export class WebviewViewPane extends ViewPane { ...@@ -142,7 +155,7 @@ export class WebviewViewPane extends ViewPane {
const webviewId = `webviewView-${this.id.replace(/[^a-z0-9]/gi, '-')}`.toLowerCase(); const webviewId = `webviewView-${this.id.replace(/[^a-z0-9]/gi, '-')}`.toLowerCase();
const webview = this.webviewService.createWebviewOverlay(webviewId, {}, {}, undefined); const webview = this.webviewService.createWebviewOverlay(webviewId, {}, {}, undefined);
webview.state = this.viewState['webviewState']; webview.state = this.viewState[storageKeys.webviewState];
this._webview = webview; this._webview = webview;
this._register(toDisposable(() => { this._register(toDisposable(() => {
...@@ -150,7 +163,7 @@ export class WebviewViewPane extends ViewPane { ...@@ -150,7 +163,7 @@ export class WebviewViewPane extends ViewPane {
})); }));
this._register(webview.onDidUpdateState(() => { this._register(webview.onDidUpdateState(() => {
this.viewState[webviewStateKey] = webview.state; this.viewState[storageKeys.webviewState] = webview.state;
})); }));
const source = this._register(new CancellationTokenSource()); const source = this._register(new CancellationTokenSource());
...@@ -164,8 +177,8 @@ export class WebviewViewPane extends ViewPane { ...@@ -164,8 +177,8 @@ export class WebviewViewPane extends ViewPane {
onDidChangeVisibility: this.onDidChangeBodyVisibility, onDidChangeVisibility: this.onDidChangeBodyVisibility,
onDispose: this.onDispose, onDispose: this.onDispose,
get title() { return self.title; }, get title(): string | undefined { return self.setTitle; },
set title(value: string) { self.updateTitle(value); }, set title(value: string | undefined) { self.updateTitle(value); },
get description(): string | undefined { return self.titleDescription; }, get description(): string | undefined { return self.titleDescription; },
set description(value: string | undefined) { self.updateTitleDescription(value); }, set description(value: string | undefined) { self.updateTitleDescription(value); },
...@@ -180,6 +193,11 @@ export class WebviewViewPane extends ViewPane { ...@@ -180,6 +193,11 @@ export class WebviewViewPane extends ViewPane {
} }
} }
protected updateTitle(value: string | undefined) {
this.setTitle = value;
super.updateTitle(typeof value === 'string' ? value : this.defaultTitle);
}
private async withProgress(task: () => Promise<void>): Promise<void> { private async withProgress(task: () => Promise<void>): Promise<void> {
return this.progressService.withProgress({ location: this.id, delay: 500 }, task); return this.progressService.withProgress({ location: this.id, delay: 500 }, task);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册