From f3bd6145a5c95cdb453fbc85401f5355079138ed Mon Sep 17 00:00:00 2001 From: Paris Date: Thu, 2 Jun 2016 13:31:38 +0300 Subject: [PATCH] Vanish selection when a key with data is being pressed --- src/xterm.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index e100e7c2..a1bdd20c 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -421,7 +421,6 @@ /** * Initialize default behavior */ - Terminal.prototype.initGlobal = function() { Terminal.bindPaste(this); Terminal.bindKeys(this); @@ -442,10 +441,11 @@ }); /** - * Contenteditable hack in order to allow right-click paste + * Contenteditable hack in order to allow right-click paste. + * Set contentEditable to true when right clicking and then set it back to false on mouse up + * in order to hide the contentEditable cursor. */ on(term.element, 'contextmenu', function (ev) { - console.log('hey'); term.element.contentEditable = true; }); @@ -514,7 +514,7 @@ this.children.push(row); return row; - } + }; /* @@ -2447,6 +2447,18 @@ key = String.fromCharCode(key); + /** + * When a key is pressed and a character is sent to the terminal, then clear any text + * selected in the terminal. + */ + if (key) { + var selectionBaseNode = window.getSelection().baseNode; + + if (selectionBaseNode && (this.element.contains(selectionBaseNode.parentElement))) { + window.getSelection().removeAllRanges(); + } + } + this.emit('keypress', key, ev); this.emit('key', key, ev); this.showCursor();