Skip to content

Commit

Permalink
Handles editor position change to refresh the webview
Browse files Browse the repository at this point in the history
  • Loading branch information
nzaytsev authored and eamodio committed Dec 18, 2024
1 parent ba3e42a commit f1d876b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/webviews/webviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export class WebviewController<
private /*readonly*/ provider!: WebviewProvider<State, SerializedState, ShowingArgs>;
private readonly webview: Webview;

private viewColumn: ViewColumn | undefined;

private constructor(
private readonly container: Container,
private readonly _commandRegistrar: WebviewCommandRegistrar,
Expand Down Expand Up @@ -184,9 +186,15 @@ export class WebviewController<
window.onDidChangeWindowState(this.onWindowStateChanged, this),
parent.webview.onDidReceiveMessage(this.onMessageReceivedCore, this),
isInEditor
? parent.onDidChangeViewState(({ webviewPanel: { visible, active } }) =>
this.onParentVisibilityChanged(visible, active),
)
? parent.onDidChangeViewState(({ webviewPanel }) => {
const { visible, active, viewColumn } = webviewPanel;
this.onParentVisibilityChanged(
visible,
active,
this.viewColumn != null && this.viewColumn !== viewColumn,
);
this.viewColumn = viewColumn;
})
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible, this.active)),
parent.onDidDispose(this.onParentDisposed, this),
...(this.provider.registerCommands?.() ?? []),
Expand Down Expand Up @@ -466,7 +474,12 @@ export class WebviewController<
}

@debug()
private onParentVisibilityChanged(visible: boolean, active?: boolean) {
private onParentVisibilityChanged(visible: boolean, active?: boolean, forceReload?: boolean) {
if (forceReload) {
void this.refresh();
return;
}

if (this.descriptor.webviewHostOptions?.retainContextWhenHidden !== true) {
if (visible) {
if (this._ready) {
Expand Down

0 comments on commit f1d876b

Please sign in to comment.