From 3217a4bee43e28378d93cc6cc6dd5cb28d1e5bda Mon Sep 17 00:00:00 2001 From: Paris Date: Sun, 19 Jun 2016 06:12:25 +0300 Subject: [PATCH] Fix cumbersome pasting with Cmd + V For some reason, setting the element's contentEditable value to true within a keyboard event, while the element has focus, did not allow pasting with clipboard, unless the element gets clicked explicitly. --- src/xterm.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index 6319570..30ec970 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -456,7 +456,7 @@ * @public */ Terminal.prototype.blur = function() { - return terminal.element.blur(); + return this.element.blur(); }; /** @@ -506,6 +506,14 @@ var term = this; term.element.contentEditable = true; + + /** + * Blur and re-focus instantly. This is due to a weird focus state on Chrome, when setting + * contentEditable to true on a focused element. + */ + term.blur(); + term.focus(); + setTimeout(function () { term.element.contentEditable = false; if (typeof callback == 'function') { @@ -544,21 +552,17 @@ * as true. */ on(term.element, 'keydown', function (ev) { + var isEditable = term.element.contentEditable === "true"; + /** * If on a Mac, lease the contentEditable value temporarily, when the user presses - * the Cmd button, in order to cope with some sync issues on Safari. + * the Cmd button, in a keydown event order to paste frictionlessly. */ - if (term.isMac && ev.keyCode == 91) { - term.leaseContentEditable(1000); - } - - if (ev.keyCode == 86) { // keyCode 96 corresponds to "v" - if (term.isMac && ev.metaKey) { - term.leaseContentEditable(); - } + if (term.isMac && ev.metaKey && !isEditable) { + term.leaseContentEditable(5000); } - if (!term.isMac && ev.keyCode == 45 && ev.shiftKey && !ev.ctrlKey) { + if (!term.isMac && ev.keyCode == 45 && ev.shiftKey && !ev.ctrlKey && !isEditable) { // Shift + Insert pastes on windows and many linuxes term.leaseContentEditable(); } @@ -730,7 +734,7 @@ this.element.classList.add('xterm'); this.element.classList.add('xterm-theme-' + this.theme); this.element.setAttribute('tabindex', 0); - this.element.spellcheck = 'false'; + this.element.spellcheck = false; /* * Create the container that will hold the lines of the terminal and then -- 2.39.5