@@ -19,11 +19,13 @@ import {TerminalInstance} from 'vs/workbench/parts/terminal/electron-browser/ter
19
19
20
20
export class TerminalPanel extends Panel {
21
21
22
- private toDispose : lifecycle . IDisposable [ ] ;
22
+ private toDispose : lifecycle . IDisposable [ ] = [ ] ;
23
+ private terminalInstances : TerminalInstance [ ] = [ ] ;
24
+
23
25
private parentDomElement : HTMLElement ;
24
26
private themeStyleElement : HTMLElement ;
25
27
private configurationHelper : TerminalConfigHelper ;
26
- private terminalInstance : TerminalInstance ;
28
+ private activeTerminalIndex : number ;
27
29
28
30
constructor (
29
31
@IConfigurationService private configurationService : IConfigurationService ,
@@ -33,12 +35,11 @@ export class TerminalPanel extends Panel {
33
35
@IThemeService private themeService : IThemeService
34
36
) {
35
37
super ( TERMINAL_PANEL_ID , telemetryService ) ;
36
- this . toDispose = [ ] ;
37
38
}
38
39
39
40
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 ) ;
42
43
}
43
44
}
44
45
@@ -49,15 +50,15 @@ export class TerminalPanel extends Panel {
49
50
this . parentDomElement . appendChild ( this . themeStyleElement ) ;
50
51
this . configurationHelper = new TerminalConfigHelper ( platform . platform , this . configurationService , this . parentDomElement ) ;
51
52
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 ) ) ;
53
54
} ) ) ;
54
55
55
56
return this . createTerminal ( ) ;
56
57
}
57
58
58
59
public setVisible ( visible : boolean ) : TPromise < void > {
59
60
if ( visible ) {
60
- if ( this . terminalInstance ) {
61
+ if ( this . terminalInstances . length > 0 ) {
61
62
this . updateFont ( ) ;
62
63
this . updateTheme ( ) ;
63
64
} else {
@@ -74,22 +75,30 @@ export class TerminalPanel extends Panel {
74
75
75
76
private createTerminal ( ) : TPromise < void > {
76
77
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 ;
78
80
this . toDispose . push ( this . themeService . onDidThemeChange ( this . updateTheme . bind ( this ) ) ) ;
79
81
this . toDispose . push ( this . configurationService . onDidUpdateConfiguration ( this . updateFont . bind ( this ) ) ) ;
80
82
resolve ( void 0 ) ;
81
83
} ) ;
82
84
}
83
85
84
86
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
+ }
87
96
}
88
97
this . terminalService . toggle ( ) ;
89
98
}
90
99
91
100
private updateTheme ( themeId ?: string ) : void {
92
- if ( ! this . terminalInstance ) {
101
+ if ( this . terminalInstances . length === 0 ) {
93
102
return ;
94
103
}
95
104
if ( ! themeId ) {
@@ -121,25 +130,24 @@ export class TerminalPanel extends Panel {
121
130
}
122
131
123
132
private updateFont ( ) : void {
124
- if ( ! this . terminalInstance ) {
133
+ if ( this . terminalInstances . length === 0 ) {
125
134
return ;
126
135
}
127
- this . terminalInstance . setFont ( this . configurationHelper . getFont ( ) ) ;
136
+ this . terminalInstances [ this . activeTerminalIndex ] . setFont ( this . configurationHelper . getFont ( ) ) ;
128
137
this . layout ( new Dimension ( this . parentDomElement . offsetWidth , this . parentDomElement . offsetHeight ) ) ;
129
138
}
130
139
131
140
132
141
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 ) ;
135
144
}
136
145
}
137
146
138
147
public dispose ( ) : void {
139
148
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 ( ) ;
143
151
}
144
152
super . dispose ( ) ;
145
153
}
0 commit comments