Pārlūkot izejas kodu

Consolidates webview parent visibility events

main
Eric Amodio pirms 1 gada
vecāks
revīzija
aa1360ddc9
1 mainītis faili ar 18 papildinājumiem un 38 dzēšanām
  1. +18
    -38
      src/webviews/webviewController.ts

+ 18
- 38
src/webviews/webviewController.ts Parādīt failu

@ -1,4 +1,4 @@
import type { Webview, WebviewPanel, WebviewPanelOnDidChangeViewStateEvent, WebviewView, WindowState } from 'vscode';
import type { Webview, WebviewPanel, WebviewView, WindowState } from 'vscode';
import { Disposable, EventEmitter, Uri, ViewColumn, window, workspace } from 'vscode';
import { getNonce } from '@env/crypto';
import type { Commands, CustomEditorIds, WebviewIds, WebviewViewIds } from '../constants';
@ -154,8 +154,10 @@ export class WebviewController<
window.onDidChangeWindowState(this.onWindowStateChanged, this),
parent.webview.onDidReceiveMessage(this.onMessageReceivedCore, this),
isInEditor
? parent.onDidChangeViewState(this.onParentViewStateChanged, this)
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible), this),
? parent.onDidChangeViewState(({ webviewPanel: { visible, active } }) =>
this.onParentVisibilityChanged(visible, active),
)
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible)),
parent.onDidDispose(this.onParentDisposed, this),
...(this.provider.registerCommands?.() ?? []),
this.provider,
@ -342,12 +344,8 @@ export class WebviewController<
this.provider.onFocusChanged?.(e.focused);
}
@debug<WebviewController<State>['onParentViewStateChanged']>({
args: { 0: e => `active=${e.webviewPanel.active}, visible=${e.webviewPanel.visible}` },
})
private onParentViewStateChanged(e: WebviewPanelOnDidChangeViewStateEvent): void {
const { active, visible } = e.webviewPanel;
@debug()
private onParentVisibilityChanged(visible: boolean, active?: boolean) {
if (this.descriptor.webviewHostOptions?.retainContextWhenHidden !== true) {
if (visible) {
if (this._suspended) {
@ -362,42 +360,24 @@ export class WebviewController<
}
if (visible) {
setContextKeys(this.descriptor.contextKeyPrefix, active);
this.provider.onActiveChanged?.(active);
if (!active) {
this.provider.onFocusChanged?.(false);
}
} else {
resetContextKeys(this.descriptor.contextKeyPrefix);
this.provider.onActiveChanged?.(false);
this.provider.onFocusChanged?.(false);
}
this.provider.onVisibilityChanged?.(visible);
}
void this.container.usage.track(`${this.descriptor.trackingFeature}:shown`);
@debug()
private onParentVisibilityChanged(visible: boolean) {
if (this.descriptor.webviewHostOptions?.retainContextWhenHidden !== true) {
if (visible) {
if (this._suspended) {
this._ready = true;
this._suspended = false;
this.provider.onReady?.();
if (active != null) {
setContextKeys(this.descriptor.contextKeyPrefix, active);
this.provider.onActiveChanged?.(active);
if (!active) {
this.provider.onFocusChanged?.(false);
}
} else {
this._ready = false;
this._suspended = true;
}
}
if (visible) {
void this.container.usage.track(`${this.descriptor.trackingFeature}:shown`);
} else {
resetContextKeys(this.descriptor.contextKeyPrefix);
if (active != null) {
this.provider.onActiveChanged?.(false);
}
this.provider.onFocusChanged?.(false);
}
this.provider.onVisibilityChanged?.(visible);
}

Notiek ielāde…
Atcelt
Saglabāt