@@ -38,6 +38,7 @@ import { Linkifier } from './Linkifier';
38
38
import { SelectionManager } from './SelectionManager' ;
39
39
import { CharMeasure } from './utils/CharMeasure' ;
40
40
import * as Browser from './shared/utils/Browser' ;
41
+ import * as Dom from './utils/Dom' ;
41
42
import * as Strings from './Strings' ;
42
43
import { MouseHelper } from './utils/MouseHelper' ;
43
44
import { clone } from './utils/Clone' ;
@@ -46,7 +47,8 @@ import { DEFAULT_ANSI_COLORS } from './renderer/ColorManager';
46
47
import { MouseZoneManager } from './input/MouseZoneManager' ;
47
48
import { AccessibilityManager } from './AccessibilityManager' ;
48
49
import { ScreenDprMonitor } from './utils/ScreenDprMonitor' ;
49
- import { ITheme , ILocalizableStrings , IMarker } from 'xterm' ;
50
+ import { ITheme , ILocalizableStrings , IMarker , IDisposable } from 'xterm' ;
51
+ import { removeTerminalFromCache } from './renderer/atlas/CharAtlas' ;
50
52
51
53
// reg + shift key mappings for digits and special chars
52
54
const KEYCODE_KEY_MAPPINGS = {
@@ -122,11 +124,13 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
122
124
rightClickSelectsWord : Browser . isMac
123
125
} ;
124
126
125
- export class Terminal extends EventEmitter implements ITerminal , IInputHandlingTerminal {
127
+ export class Terminal extends EventEmitter implements ITerminal , IDisposable , IInputHandlingTerminal {
126
128
public textarea : HTMLTextAreaElement ;
127
129
public element : HTMLElement ;
128
130
public screenElement : HTMLElement ;
129
131
132
+ private _disposables : IDisposable [ ] ;
133
+
130
134
/**
131
135
* The HTMLElement that the terminal is created in, set by Terminal.open.
132
136
*/
@@ -248,7 +252,28 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
248
252
this . _setup ( ) ;
249
253
}
250
254
255
+ public dispose ( ) : void {
256
+ super . dispose ( ) ;
257
+ this . _disposables . forEach ( d => d . dispose ( ) ) ;
258
+ this . _disposables . length = 0 ;
259
+ removeTerminalFromCache ( this ) ;
260
+ this . handler = ( ) => { } ;
261
+ this . write = ( ) => { } ;
262
+ if ( this . element && this . element . parentNode ) {
263
+ this . element . parentNode . removeChild ( this . element ) ;
264
+ }
265
+ }
266
+
267
+ /**
268
+ * @deprecated Use dispose instead.
269
+ */
270
+ public destroy ( ) : void {
271
+ this . dispose ( ) ;
272
+ }
273
+
251
274
private _setup ( ) : void {
275
+ this . _disposables = [ ] ;
276
+
252
277
Object . keys ( DEFAULT_OPTIONS ) . forEach ( ( key ) => {
253
278
if ( this . options [ key ] == null ) {
254
279
this . options [ key ] = DEFAULT_OPTIONS [ key ] ;
@@ -690,7 +715,7 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
690
715
this . on ( 'dprchange' , ( ) => this . renderer . onWindowResize ( window . devicePixelRatio ) ) ;
691
716
// dprchange should handle this case, we need this as well for browsers that don't support the
692
717
// matchMedia query.
693
- window . addEventListener ( 'resize' , ( ) => this . renderer . onWindowResize ( window . devicePixelRatio ) ) ;
718
+ this . _disposables . push ( Dom . addDisposableListener ( window , 'resize' , ( ) => this . renderer . onWindowResize ( window . devicePixelRatio ) ) ) ;
694
719
this . charMeasure . on ( 'charsizechanged' , ( ) => this . renderer . onResize ( this . cols , this . rows ) ) ;
695
720
this . renderer . on ( 'resize' , ( dimensions ) => this . viewport . syncScrollArea ( ) ) ;
696
721
@@ -1083,19 +1108,6 @@ export class Terminal extends EventEmitter implements ITerminal, IInputHandlingT
1083
1108
} ) ;
1084
1109
}
1085
1110
1086
- /**
1087
- * Destroys the terminal.
1088
- */
1089
- public destroy ( ) : void {
1090
- super . destroy ( ) ;
1091
- this . handler = ( ) => { } ;
1092
- this . write = ( ) => { } ;
1093
- if ( this . element && this . element . parentNode ) {
1094
- this . element . parentNode . removeChild ( this . element ) ;
1095
- }
1096
- // this.emit('close');
1097
- }
1098
-
1099
1111
/**
1100
1112
* Tells the renderer to refresh terminal content between two rows (inclusive) at the next
1101
1113
* opportunity.
0 commit comments