Skip to content

Commit f1d876b

Browse files
nzaytseveamodio
authored andcommitted
Handles editor position change to refresh the webview
1 parent ba3e42a commit f1d876b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/webviews/webviewController.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export class WebviewController<
154154
private /*readonly*/ provider!: WebviewProvider<State, SerializedState, ShowingArgs>;
155155
private readonly webview: Webview;
156156

157+
private viewColumn: ViewColumn | undefined;
158+
157159
private constructor(
158160
private readonly container: Container,
159161
private readonly _commandRegistrar: WebviewCommandRegistrar,
@@ -184,9 +186,15 @@ export class WebviewController<
184186
window.onDidChangeWindowState(this.onWindowStateChanged, this),
185187
parent.webview.onDidReceiveMessage(this.onMessageReceivedCore, this),
186188
isInEditor
187-
? parent.onDidChangeViewState(({ webviewPanel: { visible, active } }) =>
188-
this.onParentVisibilityChanged(visible, active),
189-
)
189+
? parent.onDidChangeViewState(({ webviewPanel }) => {
190+
const { visible, active, viewColumn } = webviewPanel;
191+
this.onParentVisibilityChanged(
192+
visible,
193+
active,
194+
this.viewColumn != null && this.viewColumn !== viewColumn,
195+
);
196+
this.viewColumn = viewColumn;
197+
})
190198
: parent.onDidChangeVisibility(() => this.onParentVisibilityChanged(this.visible, this.active)),
191199
parent.onDidDispose(this.onParentDisposed, this),
192200
...(this.provider.registerCommands?.() ?? []),
@@ -466,7 +474,12 @@ export class WebviewController<
466474
}
467475

468476
@debug()
469-
private onParentVisibilityChanged(visible: boolean, active?: boolean) {
477+
private onParentVisibilityChanged(visible: boolean, active?: boolean, forceReload?: boolean) {
478+
if (forceReload) {
479+
void this.refresh();
480+
return;
481+
}
482+
470483
if (this.descriptor.webviewHostOptions?.retainContextWhenHidden !== true) {
471484
if (visible) {
472485
if (this._ready) {

0 commit comments

Comments
 (0)