From 55c1293b4c1ad721ead3ac8aaea3c159447f8fd3 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 3 May 2018 15:51:40 +0300 Subject: [PATCH] Allow out-of-focus typing on touch devices --- client/js/keybinds.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/client/js/keybinds.js b/client/js/keybinds.js index e9a512ad..249ca291 100644 --- a/client/js/keybinds.js +++ b/client/js/keybinds.js @@ -247,27 +247,25 @@ const ignoredKeys = { 224: true, // Meta }; -if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) { - $(document.body).on("keydown", (e) => { - // Ignore if target isn't body (e.g. focused into input) - // Ignore any key that uses alt modifier - // Ignore keys defined above - if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) { - return; - } +$(document.body).on("keydown", (e) => { + // Ignore if target isn't body (e.g. focused into input) + // Ignore any key that uses alt modifier + // Ignore keys defined above + if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) { + return; + } - // Ignore all ctrl keys except for ctrl+v to allow pasting - if ((e.ctrlKey || e.metaKey) && e.which !== 86) { - return; - } - - // On enter, focus the input but do not propagate the event - // This way, a new line is not inserted - if (e.which === 13) { - input.trigger("focus"); - return false; - } + // Ignore all ctrl keys except for ctrl+v to allow pasting + if ((e.ctrlKey || e.metaKey) && e.which !== 86) { + return; + } + // On enter, focus the input but do not propagate the event + // This way, a new line is not inserted + if (e.which === 13) { input.trigger("focus"); - }); -} + return false; + } + + input.trigger("focus"); +});