Fix marker dispose unit tests

This commit is contained in:
Daniel Imms
2022-10-08 09:27:58 -07:00
parent 94c3d11239
commit d3976c05f1
2 changed files with 24 additions and 12 deletions
-1
View File
@@ -1378,7 +1378,6 @@ describe('Terminal', () => {
assert.deepEqual(disposeStack, [markers[0], markers[1]]);
// trimmed marker objs should be disposed
assert.deepEqual(disposeStack.map(el => el.isDisposed), [true, true]);
assert.deepEqual(disposeStack.map(el => (el as any)._isDisposed), [true, true]);
// trimmed markers should contain line -1
assert.deepEqual(disposeStack.map(el => el.line), [-1, -1]);
});
+24 -11
View File
@@ -4,27 +4,40 @@
*/
import { EventEmitter } from 'common/EventEmitter';
import { Disposable, toDisposable } from 'common/Lifecycle';
import { IMarker } from 'common/Types';
import { disposeArray } from 'common/Lifecycle';
import { IDisposable, IMarker } from 'common/Types';
export class Marker extends Disposable implements IMarker {
export class Marker implements IMarker {
private static _nextId = 1;
public isDisposed: boolean = false;
private _disposables: IDisposable[] = [];
private _id: number = Marker._nextId++;
public get id(): number { return this._id; }
private readonly _onDispose = this.register(new EventEmitter<void>());
public readonly onDispose = this._onDispose.event;
public get isDisposed(): boolean { return this._isDisposed; }
private readonly _onDispose = new EventEmitter<void>();
public readonly onDispose = this._onDispose.event;
constructor(
public line: number
) {
super();
this.register(toDisposable(() => {
this.line = -1;
this._onDispose.fire();
}));
}
public dispose(): void {
if (this.isDisposed) {
return;
}
this.isDisposed = true;
this.line = -1;
// Emit before super.dispose such that dispose listeners get a change to react
this._onDispose.fire();
disposeArray(this._disposables);
}
public register(disposable: IDisposable): void {
this._disposables.push(disposable);
this._disposables.length = 0;
}
}