Add multiline chat message support

This commit is contained in:
joker-x 2020-09-16 04:09:01 +02:00 committed by Jonas Herzig
parent fd8c7fe4f7
commit 94c73a8c1f
2 changed files with 17 additions and 5 deletions

View file

@ -546,8 +546,10 @@
</div>
</div>
<form data-bind="submit: submitMessageBox">
<input id="message-box" type="text" data-bind="
attr: { placeholder: messageBoxHint }, textInput: messageBox">
<textarea id="message-box" row=1 data-bind="
attr: { placeholder: messageBoxHint },
textInput: messageBox,
event: {keypress: submitOnEnter}"></textarea>
</form>
</div>
<script type="text/html" id="channel">

View file

@ -327,6 +327,14 @@ class GlobalBindings {
}
})
this.submitOnEnter = function(data, e) {
if (e.which == 13) {
this.submitMessageBox();
return false;
}
return true;
}
this.toggleToolbarOrientation = () => {
this.toolbarHorizontal(!this.toolbarHorizontal())
this.settings.toolbarVertical = !this.toolbarHorizontal()
@ -791,10 +799,12 @@ class GlobalBindings {
target = target.channel()
}
// Avoid blank message
message = sanitize(message).trim()
if (message.length == 0) return;
if (sanitize(message).trim().length == 0) return;
// Support multiline
message = message.replace(/\n\n+/g,"\n\n");
message = message.replace(/\n/g,"<br>");
// Send message
target.model.sendMessage(message)
target.model.sendMessage(anchorme(message))
if (target.users) { // Channel
this.log.push({
type: 'chat-message-self',