Create new event with emitter object to simplify code
This commit is contained in:
@@ -1071,7 +1071,7 @@ describe('Buffer', () => {
|
||||
buffer.fillViewportRows();
|
||||
const marker = buffer.addMarker(buffer.lines.length - 1);
|
||||
assert.equal(marker.line, buffer.lines.length - 1);
|
||||
buffer.lines.onTrimEmitter.fire(1);
|
||||
buffer.lines.onTrim.fire(1);
|
||||
assert.equal(marker.line, buffer.lines.length - 2);
|
||||
});
|
||||
it('should dispose of a marker if it is trimmed off the buffer', () => {
|
||||
@@ -1081,7 +1081,7 @@ describe('Buffer', () => {
|
||||
const marker = buffer.addMarker(0);
|
||||
assert.equal(marker.isDisposed, false);
|
||||
assert.equal(buffer.markers.length, 1);
|
||||
buffer.lines.onTrimEmitter.fire(1);
|
||||
buffer.lines.onTrim.fire(1);
|
||||
assert.equal(marker.isDisposed, true);
|
||||
assert.equal(buffer.markers.length, 0);
|
||||
});
|
||||
@@ -1094,7 +1094,7 @@ describe('Buffer', () => {
|
||||
marker.onDispose(() => eventStack.push('disposed'));
|
||||
assert.equal(marker.isDisposed, false);
|
||||
assert.equal(buffer.markers.length, 1);
|
||||
buffer.lines.onTrimEmitter.fire(1);
|
||||
buffer.lines.onTrim.fire(1);
|
||||
assert.equal(marker.isDisposed, true);
|
||||
assert.equal(buffer.markers.length, 0);
|
||||
assert.deepEqual(eventStack, ['disposed']);
|
||||
|
||||
@@ -463,12 +463,12 @@ export class Buffer implements IBuffer {
|
||||
let insertCountEmitted = 0;
|
||||
for (let i = insertEvents.length - 1; i >= 0; i--) {
|
||||
insertEvents[i].index += insertCountEmitted;
|
||||
this.lines.onInsertEmitter.fire(insertEvents[i]);
|
||||
this.lines.onInsert.fire(insertEvents[i]);
|
||||
insertCountEmitted += insertEvents[i].amount;
|
||||
}
|
||||
const amountToTrim = Math.max(0, originalLinesLength + countToInsert - this.lines.maxLength);
|
||||
if (amountToTrim > 0) {
|
||||
this.lines.onTrimEmitter.fire(amountToTrim);
|
||||
this.lines.onTrim.fire(amountToTrim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export function reflowLargerCreateNewLayout(lines: CircularList<IBufferLine>, to
|
||||
const countToRemove = toRemove[++nextToRemoveIndex];
|
||||
|
||||
// Tell markers that there was a deletion
|
||||
lines.onDeleteEmitter.fire({
|
||||
lines.onDelete.fire({
|
||||
index: i - countRemovedSoFar,
|
||||
amount: countToRemove
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { IBuffer, IBufferSet } from 'common/buffer/Types';
|
||||
import { IAttributeData } from 'common/Types';
|
||||
import { Buffer } from 'common/buffer/Buffer';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { EventEmitter, IEvent, initEvent } from 'common/EventEmitter';
|
||||
import { IOptionsService, IBufferService } from 'common/services/Services';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
|
||||
@@ -19,8 +19,7 @@ export class BufferSet extends Disposable implements IBufferSet {
|
||||
private _alt!: Buffer;
|
||||
private _activeBuffer!: Buffer;
|
||||
|
||||
private readonly _onBufferActivate = this.register(new EventEmitter<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
|
||||
public readonly onBufferActivate = this._onBufferActivate.event;
|
||||
public readonly onBufferActivate = this.register(initEvent<{activeBuffer: IBuffer, inactiveBuffer: IBuffer}>());
|
||||
|
||||
/**
|
||||
* Create a new BufferSet for the given terminal.
|
||||
@@ -42,7 +41,7 @@ export class BufferSet extends Disposable implements IBufferSet {
|
||||
// See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer
|
||||
this._alt = new Buffer(false, this._optionsService, this._bufferService);
|
||||
this._activeBuffer = this._normal;
|
||||
this._onBufferActivate.fire({
|
||||
this.onBufferActivate.fire({
|
||||
activeBuffer: this._normal,
|
||||
inactiveBuffer: this._alt
|
||||
});
|
||||
@@ -86,7 +85,7 @@ export class BufferSet extends Disposable implements IBufferSet {
|
||||
this._alt.clearAllMarkers();
|
||||
this._alt.clear();
|
||||
this._activeBuffer = this._normal;
|
||||
this._onBufferActivate.fire({
|
||||
this.onBufferActivate.fire({
|
||||
activeBuffer: this._normal,
|
||||
inactiveBuffer: this._alt
|
||||
});
|
||||
@@ -105,7 +104,7 @@ export class BufferSet extends Disposable implements IBufferSet {
|
||||
this._alt.x = this._normal.x;
|
||||
this._alt.y = this._normal.y;
|
||||
this._activeBuffer = this._alt;
|
||||
this._onBufferActivate.fire({
|
||||
this.onBufferActivate.fire({
|
||||
activeBuffer: this._alt,
|
||||
inactiveBuffer: this._normal
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
import { initEvent } from 'common/EventEmitter';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { IMarker } from 'common/Types';
|
||||
|
||||
@@ -15,8 +15,7 @@ export class Marker extends Disposable implements IMarker {
|
||||
|
||||
public get id(): number { return this._id; }
|
||||
|
||||
private readonly _onDispose = new EventEmitter<void>();
|
||||
public readonly onDispose = this._onDispose.event;
|
||||
public readonly onDispose = initEvent<void>();
|
||||
|
||||
constructor(
|
||||
public line: number
|
||||
@@ -31,7 +30,7 @@ export class Marker extends Disposable implements IMarker {
|
||||
this.isDisposed = true;
|
||||
this.line = -1;
|
||||
// Emit before super.dispose such that dispose listeners get a change to react
|
||||
this._onDispose.fire();
|
||||
this.onDispose.fire();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user