diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts index b4719ff7148..9074a99164c 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminal.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminal.ts @@ -58,6 +58,7 @@ export interface ITerminalService { focus(): TPromise; focusNext(): TPromise; focusPrevious(): TPromise; + hide(): TPromise; runSelectedText(): TPromise; setActiveTerminal(index: number): TPromise; toggle(): TPromise; diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts index 9528bb889e0..66b5bd65e34 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts @@ -47,7 +47,8 @@ export class TerminalPanel extends Panel { if (!dimension) { return; } - if (this.terminalInstances.length > 0) { + let activeIndex = this.terminalService.getActiveTerminalIndex(); + if (activeIndex !== -1 && this.terminalInstances.length > 0) { this.terminalInstances[this.terminalService.getActiveTerminalIndex()].layout(dimension); } } @@ -152,11 +153,14 @@ export class TerminalPanel extends Panel { this.terminalInstances[index].dispose(); this.terminalInstances.splice(index, 1); } - if (this.terminalInstances.length === 0) { - this.terminalService.toggle(); - } else { + if (this.terminalInstances.length > 0) { this.setActiveTerminal(this.terminalService.getActiveTerminalIndex()); } + if (this.terminalInstances.length === 0) { + this.terminalService.hide(); + } else { + this.terminalService.focus(); + } } private updateTheme(themeId?: string): void { @@ -202,8 +206,9 @@ export class TerminalPanel extends Panel { } public focus(): void { - if (this.terminalInstances.length > 0) { - this.terminalInstances[this.terminalService.getActiveTerminalIndex()].focus(true); + let activeIndex = this.terminalService.getActiveTerminalIndex(); + if (activeIndex !== -1 && this.terminalInstances.length > 0) { + this.terminalInstances[activeIndex].focus(true); } } diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts index 9eae9e53d5e..9183945670d 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalService.ts @@ -129,6 +129,14 @@ export class TerminalService implements ITerminalService { return this.panelService.openPanel(TERMINAL_PANEL_ID, true); } + public hide(): TPromise { + const panel = this.panelService.getActivePanel(); + if (panel && panel.getId() === TERMINAL_PANEL_ID) { + this.partService.setPanelHidden(true); + } + return TPromise.as(null); + } + public createNew(): TPromise { let self = this; return this.toggleAndGetTerminalPanel().then((terminalPanel) => { @@ -182,7 +190,7 @@ export class TerminalService implements ITerminalService { let wasActiveTerminal = (index === this.getActiveTerminalIndex()); // Push active index back if the closed process was before the active process if (this.getActiveTerminalIndex() >= index) { - this.activeTerminalIndex--; + this.activeTerminalIndex = Math.max(0, this.activeTerminalIndex - 1); } this.terminalProcesses.splice(index, 1); this._onInstancesChanged.fire();