diff --git a/src/InputHandler.ts b/src/InputHandler.ts index 95eab4a3..d0471286 100644 --- a/src/InputHandler.ts +++ b/src/InputHandler.ts @@ -15,6 +15,7 @@ import { Disposable } from './common/Lifecycle'; import { concat } from './common/TypedArrayUtils'; import { StringToUtf32, stringFromCodePoint, utf32ToString } from './core/input/TextDecoder'; import { CellData, Attributes, FgFlags, BgFlags, AttributeData } from './BufferLine'; +import { EventEmitter2, IEvent } from './common/EventEmitter2'; /** * Map collect to glevel. Used in `selectCharset`. @@ -106,6 +107,9 @@ export class InputHandler extends Disposable implements IInputHandler { private _stringDecoder: StringToUtf32 = new StringToUtf32(); private _workCell: CellData = new CellData(); + private _onCursorMove = new EventEmitter2(); + public get onCursorMove(): IEvent { return this._onCursorMove.event; } + constructor( protected _terminal: IInputHandlingTerminal, private _parser: IEscapeSequenceParser = new EscapeSequenceParser()) @@ -305,7 +309,7 @@ export class InputHandler extends Disposable implements IInputHandler { buffer = this._terminal.buffer; if (buffer.x !== cursorStartX || buffer.y !== cursorStartY) { - this._terminal.emit('cursormove'); + this._onCursorMove.fire(); } } diff --git a/src/Terminal.test.ts b/src/Terminal.test.ts index f4b717d8..2422c038 100644 --- a/src/Terminal.test.ts +++ b/src/Terminal.test.ts @@ -85,6 +85,16 @@ describe('term.js addons', () => { }); }); + describe('cursormove', () => { + it('should emit a cursormove event', (done) => { + term.on('cursormove', () => { + done(); + }); + + term.write('foo'); + }); + }); + describe(`keypress (including 'key' event)`, () => { it('should receive a string and event object', (done) => { let steps = 0; diff --git a/src/Terminal.ts b/src/Terminal.ts index c92f5da2..64178c74 100644 --- a/src/Terminal.ts +++ b/src/Terminal.ts @@ -261,7 +261,6 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this._setup(); // TODO: Replace EventEmitter with EventEmitter2 internally - this.on('cursormove', () => this._onCursorMove.fire()); this.on('linefeed', () => this._onLineFeed.fire()); this.on('selection', () => this._onSelectionChange.fire()); this.on('data', e => this._onInput.fire(e)); @@ -270,6 +269,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II // TODO: Remove these in v4 // Fire old style events from new emitters + this.onCursorMove(() => this.emit('cursormove')); this.onKey(e => this.emit('key', e.key, e.domEvent)); this.onResize(e => this.emit('resize', e)); this.onTitleChange(e => this.emit('title', e)); @@ -350,7 +350,9 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this._userScrolling = false; this._inputHandler = new InputHandler(this); + this._inputHandler.onCursorMove(() => this._onCursorMove.fire()); this.register(this._inputHandler); + // Reuse renderer if the Terminal is being recreated via a reset call. this.renderer = this.renderer || null; this.selectionManager = this.selectionManager || null; @@ -769,7 +771,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II this.viewport.onThemeChanged(this.renderer.colorManager.colors); this.register(this.viewport); - this.register(this.addDisposableListener('cursormove', () => this.renderer.onCursorMove())); + this.register(this.onCursorMove(() => this.renderer.onCursorMove())); this.register(this.onResize(() => this.renderer.onResize(this.cols, this.rows))); this.register(this.addDisposableListener('blur', () => this.renderer.onBlur())); this.register(this.addDisposableListener('focus', () => this.renderer.onFocus()));