Skip to content

Commit 1b43b07

Browse files
authored
Merge pull request microsoft#236696 from microsoft/tyriar/236517
Polish terminal toggle creation and add hideOnLastClosed setting
2 parents 8d0d731 + f7fd666 commit 1b43b07

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export const enum TerminalSettingId {
103103
EnablePersistentSessions = 'terminal.integrated.enablePersistentSessions',
104104
PersistentSessionReviveProcess = 'terminal.integrated.persistentSessionReviveProcess',
105105
HideOnStartup = 'terminal.integrated.hideOnStartup',
106+
HideOnLastClosed = 'terminal.integrated.hideOnLastClosed',
106107
CustomGlyphs = 'terminal.integrated.customGlyphs',
107108
RescaleOverlappingGlyphs = 'terminal.integrated.rescaleOverlappingGlyphs',
108109
PersistentSessionScrollback = 'terminal.integrated.persistentSessionScrollback',

src/vs/workbench/contrib/terminal/browser/terminalGroupService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class TerminalGroupService extends Disposable implements ITerminalGroupSe
8383
hidePanel(): void {
8484
// Hide the panel if the terminal is in the panel and it has no sibling views
8585
const panel = this._viewDescriptorService.getViewContainerByViewId(TERMINAL_VIEW_ID);
86-
if (panel && this._viewDescriptorService.getViewContainerModel(panel).activeViewDescriptors.length === 1) {
86+
if (panel && this._viewDescriptorService.getViewContainerModel(panel).visibleViewDescriptors.length === 1) {
8787
this._viewsService.closeView(TERMINAL_VIEW_ID);
8888
TerminalContextKeys.tabsMouse.bindTo(this._contextKeyService).set(false);
8989
}

src/vs/workbench/contrib/terminal/browser/terminalService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class TerminalService extends Disposable implements ITerminalService {
208208
// down. When shutting down the panel is locked in place so that it is restored upon next
209209
// launch.
210210
this._register(this._terminalGroupService.onDidChangeActiveInstance(instance => {
211-
if (!instance && !this._isShuttingDown) {
211+
if (!instance && !this._isShuttingDown && this._terminalConfigService.config.hideOnLastClosed) {
212212
this._terminalGroupService.hidePanel();
213213
}
214214
if (instance?.shellType) {

src/vs/workbench/contrib/terminal/browser/terminalView.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export class TerminalViewPane extends ViewPane {
5757
private _terminalTabbedView?: TerminalTabbedView;
5858
get terminalTabbedView(): TerminalTabbedView | undefined { return this._terminalTabbedView; }
5959
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;
6065
private readonly _newDropdown: MutableDisposable<DropdownWithPrimaryActionViewItem> = this._register(new MutableDisposable());
6166
private readonly _dropdownMenu: IMenu;
6267
private readonly _singleTabMenu: IMenu;
@@ -164,7 +169,8 @@ export class TerminalViewPane extends ViewPane {
164169
if (!wasInitialized) {
165170
switch (hideOnStartup) {
166171
case 'never':
167-
this._terminalService.createTerminal({ location: TerminalLocation.Panel });
172+
this._isTerminalBeingCreated = true;
173+
this._terminalService.createTerminal({ location: TerminalLocation.Panel }).finally(() => this._isTerminalBeingCreated = false);
168174
break;
169175
case 'whenEmpty':
170176
if (this._terminalService.restoredGroupCount === 0) {
@@ -175,7 +181,10 @@ export class TerminalViewPane extends ViewPane {
175181
return;
176182
}
177183

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+
}
179188
}
180189
}
181190

@@ -320,6 +329,10 @@ export class TerminalViewPane extends ViewPane {
320329
override focus() {
321330
super.focus();
322331
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+
}
323336
this._terminalGroupService.showPanel(true);
324337
return;
325338
}

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export interface ITerminalConfiguration {
211211
experimental?: {
212212
windowsUseConptyDll?: boolean;
213213
};
214+
hideOnLastClosed: boolean;
214215
}
215216

216217
export interface ITerminalFont {

src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ const terminalConfiguration: IConfigurationNode = {
549549
],
550550
default: 'never'
551551
},
552+
[TerminalSettingId.HideOnLastClosed]: {
553+
description: localize('terminal.integrated.hideOnLastClosed', "Whether to hide the terminal view when the last terminal is closed. This will only happen when the terminal is the only visible view in the view container."),
554+
type: 'boolean',
555+
default: true
556+
},
552557
[TerminalSettingId.CustomGlyphs]: {
553558
markdownDescription: localize('terminal.integrated.customGlyphs', "Whether to draw custom glyphs for block element and box drawing characters instead of using the font, which typically yields better rendering with continuous lines. Note that this doesn't work when {0} is disabled.", `\`#${TerminalSettingId.GpuAcceleration}#\``),
554559
type: 'boolean',

0 commit comments

Comments
 (0)