Skip to content

Commit f3fb6c4

Browse files
committed
Handle an array of TerminalInstance's
Part of #6458
1 parent 8a75d0b commit f3fb6c4

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ import {TerminalInstance} from 'vs/workbench/parts/terminal/electron-browser/ter
1919

2020
export class TerminalPanel extends Panel {
2121

22-
private toDispose: lifecycle.IDisposable[];
22+
private toDispose: lifecycle.IDisposable[] = [];
23+
private terminalInstances: TerminalInstance[] = [];
24+
2325
private parentDomElement: HTMLElement;
2426
private themeStyleElement: HTMLElement;
2527
private configurationHelper: TerminalConfigHelper;
26-
private terminalInstance: TerminalInstance;
28+
private activeTerminalIndex: number;
2729

2830
constructor(
2931
@IConfigurationService private configurationService: IConfigurationService,
@@ -33,12 +35,11 @@ export class TerminalPanel extends Panel {
3335
@IThemeService private themeService: IThemeService
3436
) {
3537
super(TERMINAL_PANEL_ID, telemetryService);
36-
this.toDispose = [];
3738
}
3839

3940
public layout(dimension?: Dimension): void {
40-
if (this.terminalInstance) {
41-
this.terminalInstance.layout(dimension);
41+
if (this.terminalInstances.length > 0) {
42+
this.terminalInstances[this.activeTerminalIndex].layout(dimension);
4243
}
4344
}
4445

@@ -49,15 +50,15 @@ export class TerminalPanel extends Panel {
4950
this.parentDomElement.appendChild(this.themeStyleElement);
5051
this.configurationHelper = new TerminalConfigHelper(platform.platform, this.configurationService, this.parentDomElement);
5152
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'wheel', (event: WheelEvent) => {
52-
this.terminalInstance.dispatchEvent(new WheelEvent(event.type, event));
53+
this.terminalInstances[0].dispatchEvent(new WheelEvent(event.type, event));
5354
}));
5455

5556
return this.createTerminal();
5657
}
5758

5859
public setVisible(visible: boolean): TPromise<void> {
5960
if (visible) {
60-
if (this.terminalInstance) {
61+
if (this.terminalInstances.length > 0) {
6162
this.updateFont();
6263
this.updateTheme();
6364
} else {
@@ -74,22 +75,30 @@ export class TerminalPanel extends Panel {
7475

7576
private createTerminal(): TPromise<void> {
7677
return new TPromise<void>(resolve => {
77-
this.terminalInstance = new TerminalInstance(this.configurationHelper.getShell(), this.parentDomElement, this.contextService, this.terminalService, this.onTerminalInstanceExit.bind(this));
78+
this.terminalInstances.push(new TerminalInstance(this.configurationHelper.getShell(), this.parentDomElement, this.contextService, this.terminalService, this.onTerminalInstanceExit.bind(this)));
79+
this.activeTerminalIndex = this.terminalInstances.length - 1;
7880
this.toDispose.push(this.themeService.onDidThemeChange(this.updateTheme.bind(this)));
7981
this.toDispose.push(this.configurationService.onDidUpdateConfiguration(this.updateFont.bind(this)));
8082
resolve(void 0);
8183
});
8284
}
8385

8486
private onTerminalInstanceExit(terminalInstance: TerminalInstance): void {
85-
if (this.terminalInstance === terminalInstance) {
86-
this.terminalInstance = null;
87+
for (var i = 0; i < this.terminalInstances.length; i++) {
88+
if (this.terminalInstances[i] === terminalInstance) {
89+
if (this.activeTerminalIndex === i) {
90+
this.activeTerminalIndex = -1;
91+
} else if (this.activeTerminalIndex > i) {
92+
this.activeTerminalIndex--;
93+
}
94+
this.terminalInstances.splice(i, 1);
95+
}
8796
}
8897
this.terminalService.toggle();
8998
}
9099

91100
private updateTheme(themeId?: string): void {
92-
if (!this.terminalInstance) {
101+
if (this.terminalInstances.length === 0) {
93102
return;
94103
}
95104
if (!themeId) {
@@ -121,25 +130,24 @@ export class TerminalPanel extends Panel {
121130
}
122131

123132
private updateFont(): void {
124-
if (!this.terminalInstance) {
133+
if (this.terminalInstances.length === 0) {
125134
return;
126135
}
127-
this.terminalInstance.setFont(this.configurationHelper.getFont());
136+
this.terminalInstances[this.activeTerminalIndex].setFont(this.configurationHelper.getFont());
128137
this.layout(new Dimension(this.parentDomElement.offsetWidth, this.parentDomElement.offsetHeight));
129138
}
130139

131140

132141
public focus(): void {
133-
if (this.terminalInstance) {
134-
this.terminalInstance.focus(true);
142+
if (this.terminalInstances.length > 0) {
143+
this.terminalInstances[this.activeTerminalIndex].focus(true);
135144
}
136145
}
137146

138147
public dispose(): void {
139148
this.toDispose = lifecycle.dispose(this.toDispose);
140-
if (this.terminalInstance) {
141-
this.terminalInstance.dispose();
142-
this.terminalInstance = null;
149+
while (this.terminalInstances.length > 0) {
150+
this.terminalInstances.pop().dispose();
143151
}
144152
super.dispose();
145153
}

0 commit comments

Comments
 (0)