forked from mystiq/hydrogen-web
Merge pull request #574 from vector-im/bwindels/multiline-composer-fixups
Multiline composer fixups
This commit is contained in:
commit
222c616148
1 changed files with 28 additions and 3 deletions
|
@ -34,7 +34,11 @@ export class MessageComposer extends TemplateView {
|
||||||
onKeydown: e => this._onKeyDown(e),
|
onKeydown: e => this._onKeyDown(e),
|
||||||
onInput: () => {
|
onInput: () => {
|
||||||
vm.setInput(this._input.value);
|
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…",
|
placeholder: vm.isEncrypted ? "Send an encrypted message…" : "Send a message…",
|
||||||
rows: "1"
|
rows: "1"
|
||||||
|
@ -85,14 +89,31 @@ export class MessageComposer extends TemplateView {
|
||||||
|
|
||||||
async _trySend() {
|
async _trySend() {
|
||||||
this._input.focus();
|
this._input.focus();
|
||||||
if (await this.value.sendMessage(this._input.value)) {
|
// we clear the composer while enqueuing
|
||||||
this._input.value = "";
|
// 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._adjustHeight();
|
||||||
|
};
|
||||||
|
this._input.value = "";
|
||||||
|
this._clearHeight();
|
||||||
|
try {
|
||||||
|
if (!await this.value.sendMessage(value)) {
|
||||||
|
restoreValue();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
restoreValue();
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onKeyDown(event) {
|
_onKeyDown(event) {
|
||||||
if (event.key === "Enter" && !event.shiftKey) {
|
if (event.key === "Enter" && !event.shiftKey) {
|
||||||
|
// don't insert newline into composer
|
||||||
|
event.preventDefault();
|
||||||
this._trySend();
|
this._trySend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,4 +144,8 @@ export class MessageComposer extends TemplateView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_clearHeight() {
|
||||||
|
this._input.style.removeProperty("height");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue