From 33fe5396ec837c7ddfab32571027f2e43e6b7725 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 10 Sep 2022 22:50:15 +0200 Subject: open chat keybind --- client-web/source/chat.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'client-web/source/chat.ts') diff --git a/client-web/source/chat.ts b/client-web/source/chat.ts index 877a374..bafed73 100644 --- a/client-web/source/chat.ts +++ b/client-web/source/chat.ts @@ -23,7 +23,11 @@ export class Chat extends OverlayUi { send.onkeydown = (ev) => { if (ev.code == "Enter") { - if (send.value.trim().length == 0) return // no! + if (send.value.trim().length == 0) { + // keybind for toggle chat is Enter, so lets close here + this.shown = false + return + } this.send({ text: send.value }) send.value = "" } @@ -45,6 +49,15 @@ export class Chat extends OverlayUi { reader.readAsDataURL(blob); } } + document.body.addEventListener("keydown", ev => { + // TODO is there a proper solution? + if (ev.target instanceof HTMLInputElement && !(ev.target.type == "button")) return + if (ev.code == "Enter") { + this.shown = !this.shown + if (this.shown) send.focus() + ev.preventDefault() // so focused buttons dont trigger + } + }) } send(msg: ChatMessage) { -- cgit v1.2.3-70-g09d2