Fix other leaking listeners

This commit is contained in:
Daniel Imms
2020-05-03 14:37:20 -07:00
parent b75e42a56c
commit 06b8d36cf0
10 changed files with 44 additions and 16 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
this._instantiationService = new InstantiationService();
this.optionsService = new OptionsService(options);
this._instantiationService.setService(IOptionsService, this.optionsService);
this._bufferService = this._instantiationService.createInstance(BufferService);
this._bufferService = this.register(this._instantiationService.createInstance(BufferService));
this._instantiationService.setService(IBufferService, this._bufferService);
this._logService = this._instantiationService.createInstance(LogService);
this._instantiationService.setService(ILogService, this._logService);
+15
View File
@@ -47,3 +47,18 @@ export abstract class Disposable implements IDisposable {
}
}
}
/**
* Dispose of all disposables in an array and set its length to 0.
*/
export function disposeArray(disposables: IDisposable[]): void {
disposables.forEach(d => d.dispose());
disposables.length = 0;
}
/**
* Creates a disposable that will dispose of an array of disposables when disposed.
*/
export function getDisposeArrayDisposable(array: IDisposable[]): IDisposable {
return { dispose: () => disposeArray(array) };
}
+5 -2
View File
@@ -8,18 +8,19 @@ import { IAttributeData } from 'common/Types';
import { Buffer } from 'common/buffer/Buffer';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { IOptionsService, IBufferService } from 'common/services/Services';
import { Disposable } from 'common/Lifecycle';
/**
* The BufferSet represents the set of two buffers used by xterm terminals (normal and alt) and
* provides also utilities for working with them.
*/
export class BufferSet implements IBufferSet {
export class BufferSet extends Disposable implements IBufferSet {
private _normal: Buffer;
private _alt: Buffer;
private _activeBuffer: Buffer;
private _onBufferActivate = new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>();
private _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
public get onBufferActivate(): IEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}> { return this._onBufferActivate.event; }
/**
@@ -30,6 +31,8 @@ export class BufferSet implements IBufferSet {
optionsService: IOptionsService,
bufferService: IBufferService
) {
super();
this._normal = new Buffer(true, optionsService, bufferService);
this._normal.fillViewportRows();
+2 -2
View File
@@ -3,7 +3,7 @@
* @license MIT
*/
import { IAttributeData, ICircularList, IBufferLine, ICellData, IMarker, ICharset } from 'common/Types';
import { IAttributeData, ICircularList, IBufferLine, ICellData, IMarker, ICharset, IDisposable } from 'common/Types';
import { IEvent } from 'common/EventEmitter';
// BufferIndex denotes a position in the buffer: [rowIndex, colIndex]
@@ -47,7 +47,7 @@ export interface IBuffer {
addMarker(y: number): IMarker;
}
export interface IBufferSet {
export interface IBufferSet extends IDisposable {
alt: IBuffer;
normal: IBuffer;
active: IBuffer;
+9 -1
View File
@@ -7,11 +7,12 @@ import { IBufferService, IOptionsService } from 'common/services/Services';
import { BufferSet } from 'common/buffer/BufferSet';
import { IBufferSet, IBuffer } from 'common/buffer/Types';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { Disposable } from 'common/Lifecycle';
export const MINIMUM_COLS = 2; // Less than 2 can mess with wide chars
export const MINIMUM_ROWS = 1;
export class BufferService implements IBufferService {
export class BufferService extends Disposable implements IBufferService {
public serviceBrand: any;
public cols: number;
@@ -28,11 +29,17 @@ export class BufferService implements IBufferService {
constructor(
@IOptionsService private _optionsService: IOptionsService
) {
super();
this.cols = Math.max(_optionsService.options.cols, MINIMUM_COLS);
this.rows = Math.max(_optionsService.options.rows, MINIMUM_ROWS);
this.buffers = new BufferSet(_optionsService, this);
}
public dispose(): void {
super.dispose();
this.buffers.dispose();
}
public resize(cols: number, rows: number): void {
this.cols = cols;
this.rows = rows;
@@ -42,6 +49,7 @@ export class BufferService implements IBufferService {
}
public reset(): void {
this.buffers.dispose();
this.buffers = new BufferSet(this._optionsService, this);
this.isUserScrolling = false;
}