From 97d8a8cce6100c4a2d2c67e537d0ddc842f0b263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Sun, 2 Aug 2020 11:56:16 +0200 Subject: [PATCH] Fix handling newlines in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not possible to make a newline when already holding Shift, for example to type an uppercase character. Fix that. Signed-off-by: Nikola Forró --- webroot/js/message.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/webroot/js/message.js b/webroot/js/message.js index 86aa5aee3..4f2645f1b 100644 --- a/webroot/js/message.js +++ b/webroot/js/message.js @@ -78,6 +78,8 @@ class MessagingInterface { this.inputChangeUserName.addEventListener('keydown', this.handleUsernameKeydown.bind(this)); this.formMessageInput.addEventListener('keydown', this.handleMessageInputKeydown.bind(this)); + this.formMessageInput.addEventListener('keyup', this.handleMessageInputKeyup.bind(this)); + this.formMessageInput.addEventListener('blur', this.handleMessageInputBlur.bind(this)); this.btnSubmitMessage.addEventListener('click', this.handleSubmitChatButton.bind(this)); this.initLocalStates(); @@ -199,12 +201,10 @@ class MessagingInterface { if (!this.prepNewLine) { this.submitChat(value); event.preventDefault(); + this.prepNewLine = false; return; } - this.prepNewLine = false; - } else { - this.prepNewLine = false; } if (event.keyCode === 16 || event.keyCode === 17) { // ctrl, shift this.prepNewLine = true; @@ -221,6 +221,16 @@ class MessagingInterface { } } + handleMessageInputKeyup(event) { + if (event.keyCode === 16 || event.keyCode === 17) { // ctrl, shift + this.prepNewLine = false; + } + } + + handleMessageInputBlur(event) { + this.prepNewLine = false; + } + handleSubmitChatButton(event) { var value = this.formMessageInput.value.trim(); if (value) {