diff options
-rw-r--r-- | client-web/source/chat.ts | 15 |
1 files changed, 14 insertions, 1 deletions
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) { |