@@ -160,35 +160,27 @@ export class EditorViewExtended extends EditorView {
160
160
}
161
161
162
162
/**
163
- * Get the WebView tab for a given tab group and title. If the tab is not
164
- * currently active, it will be selected unless `throwIfTitleNotAlreadyActive`
165
- * is set to true, in which case it will throw an error.
163
+ * Switch to a TextEditor tab with the given title + optional group index.
164
+ * Throws if a matching Editor is found that isn't associated with a WebView.
166
165
* @param groupIndex zero based index for the editor group
167
166
* @param title title of the tab
168
- * @param throwIfTitleNotAlreadyActive if true, throw if the tab is not already active
169
167
* @returns Promise resolving to `WebViewExtended` object
170
168
*/
171
169
async openWebView (
172
- groupIndex : number ,
173
170
title : string ,
174
- throwIfTitleNotAlreadyActive = false
171
+ groupIndex ?: number
175
172
) : Promise < WebViewExtended > {
176
- const group = await this . getEditorGroup ( groupIndex ) ;
173
+ const group = await this . getEditorGroup ( groupIndex ?? 0 ) ;
177
174
178
- const activeTab = await group . getActiveTab ( ) ;
179
- const activeTitle = activeTab && ( await activeTab ?. getTitle ( ) ) ;
180
- const isTitleAlreadyActive = activeTitle === title ;
175
+ const tab = await group . getTabByTitle ( title ) ;
176
+ const resourceName = await tab . getAttribute ( 'data-resource-name' ) ;
177
+ const isWebView = resourceName . startsWith ( 'webview-' ) ;
181
178
182
- if ( throwIfTitleNotAlreadyActive && ! isTitleAlreadyActive ) {
183
- throw new Error (
184
- `Expected tab title to be "${ title } ", but was "${ activeTitle } "`
185
- ) ;
179
+ if ( ! isWebView ) {
180
+ throw new Error ( 'Tab is not associated with a WebView' ) ;
186
181
}
187
182
188
- if ( ! isTitleAlreadyActive ) {
189
- const tab = await group . getTabByTitle ( title ) ;
190
- await tab . select ( ) ;
191
- }
183
+ await tab . select ( ) ;
192
184
193
185
return new WebViewExtended ( group ) . wait ( ) ;
194
186
}
0 commit comments