From f4e32eee497d294decdd5b8c30939e02826cf894 Mon Sep 17 00:00:00 2001 From: CHaBou Date: Mon, 22 Jan 2018 18:12:03 +0100 Subject: [PATCH] Cursor api (#2629) * Add onCursorMove API on Term --- lib/components/term.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/components/term.js b/lib/components/term.js index 80d3c2ea..312c3ea3 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -106,6 +106,20 @@ export default class Term extends PureComponent { }); } + if (props.onCursorMove) { + this.term.on('cursormove', () => { + const cursorFrame = { + x: this.term.buffer.x * this.term.renderer.dimensions.actualCellWidth, + y: this.term.buffer.y * this.term.renderer.dimensions.actualCellHeight, + width: this.term.renderer.dimensions.actualCellWidth, + height: this.term.renderer.dimensions.actualCellHeight, + col: this.term.buffer.y, + row: this.term.buffer.x + }; + props.onCursorMove(cursorFrame); + }); + } + window.addEventListener('resize', this.onWindowResize, { passive: true }); @@ -271,7 +285,7 @@ export default class Term extends PureComponent { // instead of invoking `destroy`, since it will make the // term insta un-attachable in the future (which we need // to do in case of splitting, see `componentDidMount` - ['title', 'focus', 'data', 'resize'].forEach(type => this.term.removeAllListeners(type)); + ['title', 'focus', 'data', 'resize', 'cursormove'].forEach(type => this.term.removeAllListeners(type)); window.removeEventListener('resize', this.onWindowResize, { passive: true