Handle enter key in a more relaxed way

This commit is contained in:
Sebastian J. Wolf 2020-09-29 21:00:23 +02:00
parent 35e9373f49
commit f03da2127d

View file

@ -136,20 +136,14 @@ Page {
attachmentPreviewRow.fileProperties = {}; attachmentPreviewRow.fileProperties = {};
} }
function controlEnterKey() { function controlSendButton() {
if (newMessageTextField.text.length !== 0 if (newMessageTextField.text.length !== 0
|| attachmentPreviewRow.isPicture || attachmentPreviewRow.isPicture
|| attachmentPreviewRow.isDocument || attachmentPreviewRow.isDocument
|| attachmentPreviewRow.isVideo) { || attachmentPreviewRow.isVideo) {
newMessageSendButton.enabled = true; newMessageSendButton.enabled = true;
if (tdLibWrapper.getSendByEnter()) {
EnterKey.enabled = true;
}
} else { } else {
newMessageSendButton.enabled = false; newMessageSendButton.enabled = false;
if (tdLibWrapper.getSendByEnter()) {
EnterKey.enabled = false;
}
} }
} }
@ -172,7 +166,7 @@ Page {
tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId);
} }
} }
controlEnterKey(); controlSendButton();
} }
Component.onCompleted: { Component.onCompleted: {
@ -857,7 +851,7 @@ Page {
attachmentPreviewRow.fileProperties = selectedContentProperties; attachmentPreviewRow.fileProperties = selectedContentProperties;
attachmentPreviewRow.isPicture = true; attachmentPreviewRow.isPicture = true;
attachmentPreviewRow.visible = true; attachmentPreviewRow.visible = true;
controlEnterKey(); controlSendButton();
} }
} }
} }
@ -871,7 +865,7 @@ Page {
attachmentPreviewRow.fileProperties = selectedContentProperties; attachmentPreviewRow.fileProperties = selectedContentProperties;
attachmentPreviewRow.isVideo = true; attachmentPreviewRow.isVideo = true;
attachmentPreviewRow.visible = true; attachmentPreviewRow.visible = true;
controlEnterKey(); controlSendButton();
} }
} }
} }
@ -885,7 +879,7 @@ Page {
attachmentPreviewRow.fileProperties = selectedContentProperties; attachmentPreviewRow.fileProperties = selectedContentProperties;
attachmentPreviewRow.isDocument = true; attachmentPreviewRow.isDocument = true;
attachmentPreviewRow.visible = true; attachmentPreviewRow.visible = true;
controlEnterKey(); controlSendButton();
} }
} }
} }
@ -955,7 +949,7 @@ Page {
icon.source: "image://theme/icon-m-clear" icon.source: "image://theme/icon-m-clear"
onClicked: { onClicked: {
clearAttachmentPreviewRow(); clearAttachmentPreviewRow();
controlEnterKey(); controlSendButton();
} }
} }
@ -1029,15 +1023,16 @@ Page {
} }
} }
EnterKey.enabled: tdLibWrapper.getSendByEnter() ? text.length > 0 : true;
Component.onCompleted: { Component.onCompleted: {
if (tdLibWrapper.getSendByEnter()) { if (tdLibWrapper.getSendByEnter()) {
EnterKey.iconSource = "image://theme/icon-m-chat"; EnterKey.iconSource = "image://theme/icon-m-chat";
EnterKey.enabled = false;
} }
} }
onTextChanged: { onTextChanged: {
controlEnterKey(); controlSendButton();
} }
} }