Skip to content

Commit

Permalink
webiew: add support for activeWebviewPanelId
Browse files Browse the repository at this point in the history
The commit adds support for the `activeWebviewPanelId`
when-context-clause.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Feb 14, 2023
1 parent ac339db commit 7df1167
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/plugin-ext/src/main/browser/webview/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { FileOperationError, FileOperationResult } from '@theia/filesystem/lib/c
import { BinaryBufferReadableStream } from '@theia/core/lib/common/buffer';
import { ViewColumn } from '../../../plugin/types-impl';
import { ExtractableWidget } from '@theia/core/lib/browser/widgets/extractable-widget';
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';

// Style from core
const TRANSPARENT_OVERLAY_STYLE = 'theia-transparent-overlay';
Expand Down Expand Up @@ -105,6 +106,11 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
// On `mousedown` we put a transparent div over the `iframe` to avoid losing the mouse tacking.
protected transparentOverlay: HTMLElement;

protected _activeWebviewPanelId: ContextKey<string | undefined>;
get activeWebviewPanelId(): ContextKey<string | undefined> {
return this._activeWebviewPanelId;
}

@inject(WebviewWidgetIdentifier)
readonly identifier: WebviewWidgetIdentifier;

Expand Down Expand Up @@ -144,6 +150,9 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
@inject(WebviewResourceCache)
protected readonly resourceCache: WebviewResourceCache;

@inject(ContextKeyService)
protected readonly contextKeyService: ContextKeyService;

viewState: WebviewPanelViewState = {
visible: false,
active: false,
Expand Down Expand Up @@ -202,6 +211,15 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
this.transparentOverlay.style.display = 'none';
}
}));

this._activeWebviewPanelId = this.contextKeyService.createKey<string | undefined>('activeWebviewPanelId', undefined);
this.toDispose.push(this.onDidChangeVisibility(() => {
if (this.isVisible) {
this.activeWebviewPanelId.set(this.viewType);
} else {
this.activeWebviewPanelId.set(undefined);
}
}));
}

protected override onBeforeAttach(msg: Message): void {
Expand Down

0 comments on commit 7df1167

Please sign in to comment.