From fc1b9abe66f7a9c0c53cf16da7997e879c02579f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 5 Nov 2021 18:36:38 +0100 Subject: [PATCH 1/2] don't add line when hitting enter to send --- src/platform/web/ui/session/room/MessageComposer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/web/ui/session/room/MessageComposer.js b/src/platform/web/ui/session/room/MessageComposer.js index 08048b80..6bb44ee0 100644 --- a/src/platform/web/ui/session/room/MessageComposer.js +++ b/src/platform/web/ui/session/room/MessageComposer.js @@ -93,6 +93,8 @@ export class MessageComposer extends TemplateView { _onKeyDown(event) { if (event.key === "Enter" && !event.shiftKey) { + // don't insert newline into composer + event.preventDefault(); this._trySend(); } } From 44e7e25cab587bde42436d173dc71597685c3b8a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 5 Nov 2021 18:36:59 +0100 Subject: [PATCH 2/2] clear height while sending or clearing, also fix #572 in the process --- .../web/ui/session/room/MessageComposer.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/platform/web/ui/session/room/MessageComposer.js b/src/platform/web/ui/session/room/MessageComposer.js index 6bb44ee0..3863dddd 100644 --- a/src/platform/web/ui/session/room/MessageComposer.js +++ b/src/platform/web/ui/session/room/MessageComposer.js @@ -34,7 +34,11 @@ export class MessageComposer extends TemplateView { onKeydown: e => this._onKeyDown(e), onInput: () => { vm.setInput(this._input.value); - this._adjustHeight(); + if (this._input.value) { + this._adjustHeight(); + } else { + this._clearHeight(); + } }, placeholder: vm.isEncrypted ? "Send an encrypted messageā€¦" : "Send a messageā€¦", rows: "1" @@ -85,9 +89,24 @@ export class MessageComposer extends TemplateView { async _trySend() { this._input.focus(); - if (await this.value.sendMessage(this._input.value)) { - this._input.value = ""; + // we clear the composer while enqueuing + // and restore it when that didn't work somehow + // to prevent the user from sending the message + // every time they hit enter while it's still enqueuing. + const {value} = this._input; + const restoreValue = () => { + this._input.value = value; this._adjustHeight(); + }; + this._input.value = ""; + this._clearHeight(); + try { + if (!await this.value.sendMessage(value)) { + restoreValue(); + } + } catch (err) { + restoreValue(); + console.error(err); } } @@ -125,4 +144,8 @@ export class MessageComposer extends TemplateView { }); } + _clearHeight() { + this._input.style.removeProperty("height"); + } + }