From 1b6d925524f30148ead6c46326a0d47964d120b5 Mon Sep 17 00:00:00 2001 From: chabou Date: Sat, 7 Jan 2017 02:46:54 +0100 Subject: [PATCH] Prevent loosing focus after a char composition ended by Tab key. Fix #1341 (#1349) --- lib/hterm.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/hterm.js b/lib/hterm.js index 3d69d05e..287cf398 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -182,11 +182,22 @@ hterm.Terminal.prototype.copySelectionToClipboard = function () { } }; +let lastEventTimeStamp; +let lastEventKey; // passthrough all the commands that are meant to control // hyper and not the terminal itself const oldKeyDown = hterm.Keyboard.prototype.onKeyDown_; hterm.Keyboard.prototype.onKeyDown_ = function (e) { const modifierKeysConf = this.terminal.modifierKeys; + if (e.timeStamp === lastEventTimeStamp && e.key === lastEventKey) { + // Event was already processed. + // It seems to occur after a char composition ended by Tab and cause a blur. + // See https://github.com/zeit/hyper/issues/1341 + e.preventDefault(); + return; + } + lastEventTimeStamp = e.timeStamp; + lastEventKey = e.key; if (e.altKey && e.which !== 16 && // Ignore other modifer keys