|
1 | | -import { CancellationTokenSource, Uri, ViewColumn, window } from "vscode"; |
| 1 | +import { |
| 2 | + CancellationTokenSource, |
| 3 | + Tab, |
| 4 | + TabInputWebview, |
| 5 | + Uri, |
| 6 | + ViewColumn, |
| 7 | + window, |
| 8 | +} from "vscode"; |
2 | 9 | import { |
3 | 10 | AbstractWebview, |
4 | 11 | WebviewPanelConfig, |
@@ -150,26 +157,28 @@ export class ModelEditorView extends AbstractWebview< |
150 | 157 |
|
151 | 158 | private isAModelEditorOpen(): boolean { |
152 | 159 | return window.tabGroups.all.some((tabGroup) => |
153 | | - tabGroup.tabs.some((tab) => { |
154 | | - const viewType: string | undefined = (tab.input as any)?.viewType; |
155 | | - // The viewType has a prefix, such as "mainThreadWebview-", but if the |
156 | | - // suffix matches that should be enough to identify the view. |
157 | | - return viewType && viewType.endsWith("model-editor"); |
158 | | - }), |
| 160 | + tabGroup.tabs.some((tab) => this.isTabModelEditorView(tab)), |
159 | 161 | ); |
160 | 162 | } |
161 | 163 |
|
162 | 164 | private isAModelEditorActive(): boolean { |
163 | 165 | return window.tabGroups.all.some((tabGroup) => |
164 | | - tabGroup.tabs.some((tab) => { |
165 | | - const viewType: string | undefined = (tab.input as any)?.viewType; |
166 | | - // The viewType has a prefix, such as "mainThreadWebview-", but if the |
167 | | - // suffix matches that should be enough to identify the view. |
168 | | - return viewType && viewType.endsWith("model-editor") && tab.isActive; |
169 | | - }), |
| 166 | + tabGroup.tabs.some( |
| 167 | + (tab) => this.isTabModelEditorView(tab) && tab.isActive, |
| 168 | + ), |
170 | 169 | ); |
171 | 170 | } |
172 | 171 |
|
| 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 | + |
173 | 182 | protected async getPanelConfig(): Promise<WebviewPanelConfig> { |
174 | 183 | return { |
175 | 184 | viewId: "model-editor", |
|
0 commit comments