From fdd321311ed19d1c39728973f4b07231ad3200f7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 16 Mar 2018 18:37:12 +0200 Subject: [PATCH] Keep input reference as jquery object --- client/js/keybinds.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/js/keybinds.js b/client/js/keybinds.js index 0080d08b..fa2da80e 100644 --- a/client/js/keybinds.js +++ b/client/js/keybinds.js @@ -3,7 +3,7 @@ const $ = require("jquery"); const Mousetrap = require("mousetrap"); const wrapCursor = require("undate").wrapCursor; -const input = $("#input").get(0); +const input = $("#input"); const sidebar = $("#sidebar"); const windows = $("#windows"); const contextMenuContainer = $("#context-menu-container"); @@ -107,8 +107,10 @@ const colorsHotkeys = { for (const hotkey in colorsHotkeys) { Mousetrap.bind("mod+" + hotkey, function(e) { + const inputElement = input.get(0); + // Do not handle modifier hotkeys if input is not focused - if (document.activeElement !== input) { + if (document.activeElement !== inputElement) { return; } @@ -116,7 +118,11 @@ for (const hotkey in colorsHotkeys) { const modifier = colorsHotkeys[e.key]; - wrapCursor(input, modifier, input.selectionStart === input.selectionEnd ? "" : modifier); + wrapCursor( + inputElement, + modifier, + inputElement.selectionStart === inputElement.selectionEnd ? "" : modifier + ); }); }