From 20fecd68915bcdadf59356680c992b305a04090d Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Fri, 24 Dec 2021 00:42:17 +0000 Subject: [PATCH] Focus the chat whenever a button is pressed anywhere --- frontend/lib/chat.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/lib/chat.mjs b/frontend/lib/chat.mjs index bc06473..a5ff30e 100644 --- a/frontend/lib/chat.mjs +++ b/frontend/lib/chat.mjs @@ -43,6 +43,15 @@ export const setupChat = async (socket) => { document.querySelector("#chatbox-container").style["display"] = "block"; setupChatboxEvents(socket); + window.addEventListener("keydown", event => { + try { + const isSelectionEmpty = window.getSelection().toString().length === 0; + if (event.code.match(/Key\w/) && isSelectionEmpty) + document.querySelector("#chatbox-send > input").focus() + } catch (_err) { + } + }); + fixChatSize(); window.addEventListener("resize", () => { fixChatSize();