From 05398367147bd5b3c3990defb032a349ac8c5d22 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Fri, 13 May 2022 15:38:18 +0530 Subject: [PATCH] Fix space and enter focus message field --- src/client/event/hotkeys.js | 39 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/client/event/hotkeys.js b/src/client/event/hotkeys.js index 393dc87..30594e4 100644 --- a/src/client/event/hotkeys.js +++ b/src/client/event/hotkeys.js @@ -2,34 +2,25 @@ import { openSearch, toggleRoomSettings } from '../action/navigation'; import navigation from '../state/navigation'; import { markAsRead } from '../action/notifications'; -// describes which keys should auto-focus the message field function shouldFocusMessageField(code) { - // should focus on alphanumeric values, and backspace - if (code.startsWith('Key')) { - return true; - } - if (code.startsWith('Digit')) { - return true; - } - if (code === 'Backspace') { - return true; - } - - // do not focus if super key is pressed - if (code.startsWith('Meta')) { // chrome - return false; - } - if (code.startsWith('OS')) { // firefox - return false; - } - // do not focus on F keys - if (/^F\d+$/.test(code)) { - return false; - } + if (/^F\d+$/.test(code)) return false; // do not focus on numlock/scroll lock - if (code === 'NumLock' || code === 'ScrollLock') { + if ( + code.metaKey + || code.startsWith('OS') + || code.startsWith('Meta') + || code.startsWith('Shift') + || code.startsWith('Alt') + || code.startsWith('Control') + || code.startsWith('Arrow') + || code === 'Tab' + || code === 'Space' + || code === 'Enter' + || code === 'NumLock' + || code === 'ScrollLock' + ) { return false; }