Skip to content

Commit bd67afe

Browse files
committed
Extract logic into reusable function
1 parent 4c9ce2d commit bd67afe

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CancellationTokenSource,
3+
Tab,
34
TabInputWebview,
45
Uri,
56
ViewColumn,
@@ -156,30 +157,28 @@ export class ModelEditorView extends AbstractWebview<
156157

157158
private isAModelEditorOpen(): boolean {
158159
return window.tabGroups.all.some((tabGroup) =>
159-
tabGroup.tabs.some((tab) => {
160-
const viewType =
161-
tab.input instanceof TabInputWebview ? tab.input.viewType : undefined;
162-
163-
// The viewType has a prefix, such as "mainThreadWebview-", but if the
164-
// suffix matches that should be enough to identify the view.
165-
return viewType && viewType.endsWith("model-editor");
166-
}),
160+
tabGroup.tabs.some((tab) => this.isTabModelEditorView(tab)),
167161
);
168162
}
169163

170164
private isAModelEditorActive(): boolean {
171165
return window.tabGroups.all.some((tabGroup) =>
172-
tabGroup.tabs.some((tab) => {
173-
const viewType =
174-
tab.input instanceof TabInputWebview ? tab.input.viewType : undefined;
175-
176-
// The viewType has a prefix, such as "mainThreadWebview-", but if the
177-
// suffix matches that should be enough to identify the view.
178-
return viewType && viewType.endsWith("model-editor") && tab.isActive;
179-
}),
166+
tabGroup.tabs.some(
167+
(tab) => this.isTabModelEditorView(tab) && tab.isActive,
168+
),
180169
);
181170
}
182171

172+
private isTabModelEditorView(tab: Tab): boolean {
173+
if (!(tab.input instanceof TabInputWebview)) {
174+
return false;
175+
}
176+
177+
// The viewType has a prefix, such as "mainThreadWebview-", but if the
178+
// suffix matches that should be enough to identify the view.
179+
return tab.input.viewType.endsWith("model-editor");
180+
}
181+
183182
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
184183
return {
185184
viewId: "model-editor",

0 commit comments

Comments
 (0)