Merge pull request #2855 from github/charisk/tidy-castings

Don't use 'as any' when checking open view
This commit is contained in:
Charis Kyriakou
2023-09-25 13:52:14 +01:00
committed by GitHub

View File

@@ -1,4 +1,11 @@
import { CancellationTokenSource, Uri, ViewColumn, window } from "vscode";
import {
CancellationTokenSource,
Tab,
TabInputWebview,
Uri,
ViewColumn,
window,
} from "vscode";
import {
AbstractWebview,
WebviewPanelConfig,
@@ -150,26 +157,28 @@ export class ModelEditorView extends AbstractWebview<
private isAModelEditorOpen(): boolean {
return window.tabGroups.all.some((tabGroup) =>
tabGroup.tabs.some((tab) => {
const viewType: string | undefined = (tab.input as any)?.viewType;
// The viewType has a prefix, such as "mainThreadWebview-", but if the
// suffix matches that should be enough to identify the view.
return viewType && viewType.endsWith("model-editor");
}),
tabGroup.tabs.some((tab) => this.isTabModelEditorView(tab)),
);
}
private isAModelEditorActive(): boolean {
return window.tabGroups.all.some((tabGroup) =>
tabGroup.tabs.some((tab) => {
const viewType: string | undefined = (tab.input as any)?.viewType;
// The viewType has a prefix, such as "mainThreadWebview-", but if the
// suffix matches that should be enough to identify the view.
return viewType && viewType.endsWith("model-editor") && tab.isActive;
}),
tabGroup.tabs.some(
(tab) => this.isTabModelEditorView(tab) && tab.isActive,
),
);
}
private isTabModelEditorView(tab: Tab): boolean {
if (!(tab.input instanceof TabInputWebview)) {
return false;
}
// The viewType has a prefix, such as "mainThreadWebview-", but if the
// suffix matches that should be enough to identify the view.
return tab.input.viewType.endsWith("model-editor");
}
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
return {
viewId: "model-editor",