@@ -57,6 +57,11 @@ export class TerminalViewPane extends ViewPane {
57
57
private _terminalTabbedView ?: TerminalTabbedView ;
58
58
get terminalTabbedView ( ) : TerminalTabbedView | undefined { return this . _terminalTabbedView ; }
59
59
private _isInitialized : boolean = false ;
60
+ /**
61
+ * Tracks an active promise of terminal creation requested by this component. This helps prevent
62
+ * double creation for example when toggling a terminal's visibility and focusing it.
63
+ */
64
+ private _isTerminalBeingCreated : boolean = false ;
60
65
private readonly _newDropdown : MutableDisposable < DropdownWithPrimaryActionViewItem > = this . _register ( new MutableDisposable ( ) ) ;
61
66
private readonly _dropdownMenu : IMenu ;
62
67
private readonly _singleTabMenu : IMenu ;
@@ -164,7 +169,8 @@ export class TerminalViewPane extends ViewPane {
164
169
if ( ! wasInitialized ) {
165
170
switch ( hideOnStartup ) {
166
171
case 'never' :
167
- this . _terminalService . createTerminal ( { location : TerminalLocation . Panel } ) ;
172
+ this . _isTerminalBeingCreated = true ;
173
+ this . _terminalService . createTerminal ( { location : TerminalLocation . Panel } ) . finally ( ( ) => this . _isTerminalBeingCreated = false ) ;
168
174
break ;
169
175
case 'whenEmpty' :
170
176
if ( this . _terminalService . restoredGroupCount === 0 ) {
@@ -175,7 +181,10 @@ export class TerminalViewPane extends ViewPane {
175
181
return ;
176
182
}
177
183
178
- this . _terminalService . createTerminal ( { location : TerminalLocation . Panel } ) ;
184
+ if ( ! this . _isTerminalBeingCreated ) {
185
+ this . _isTerminalBeingCreated = true ;
186
+ this . _terminalService . createTerminal ( { location : TerminalLocation . Panel } ) . finally ( ( ) => this . _isTerminalBeingCreated = false ) ;
187
+ }
179
188
}
180
189
}
181
190
@@ -320,6 +329,10 @@ export class TerminalViewPane extends ViewPane {
320
329
override focus ( ) {
321
330
super . focus ( ) ;
322
331
if ( this . _terminalService . connectionState === TerminalConnectionState . Connected ) {
332
+ if ( this . _terminalGroupService . instances . length === 0 && ! this . _isTerminalBeingCreated ) {
333
+ this . _isTerminalBeingCreated = true ;
334
+ this . _terminalService . createTerminal ( { location : TerminalLocation . Panel } ) . finally ( ( ) => this . _isTerminalBeingCreated = false ) ;
335
+ }
323
336
this . _terminalGroupService . showPanel ( true ) ;
324
337
return ;
325
338
}
0 commit comments