From 14cd79a415f349ca881872d9df0fdc92b9186b84 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 24 Jun 2020 22:01:13 -0400 Subject: [PATCH] feat: support ctrl + enter in chat input --- .../AppLayouts/Chat/ChatColumn/ChatInput.qml | 61 +++++++++++-------- ui/shared/StyledTArea.qml | 7 +++ 2 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 ui/shared/StyledTArea.qml diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml index 52509c645a..a90b9eded1 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatInput.qml @@ -10,33 +10,48 @@ Rectangle { visible: chatsModel.activeChannel.chatType != Constants.chatTypePrivateGroupChat || chatsModel.activeChannel.isMember(profileModel.profile.pubKey) + function onEnter(event){ + if(!(event.modifiers & Qt.ControlModifier) && !(event.modifiers & Qt.ShiftModifier)){ + if(txtData.text.trim().length > 0){ + chatsModel.sendMessage(txtData.text.trim()); + txtData.text = ""; + } + } else { + txtData.text = txtData.text + "\n"; + txtData.cursorPosition = txtData.text.length + } + event.accepted = true; + } + RowLayout { spacing: 0 anchors.fill: parent - StyledTextField { + + ScrollView { + anchors.fill: parent Layout.fillWidth: true Layout.fillHeight: true - Layout.preferredWidth: parent.width - sendBtns.width - id: txtData - text: "" - leftPadding: 12 - rightPadding: Theme.padding - font.pixelSize: 14 - placeholderText: qsTr("Type a message...") + StyledTArea { + Layout.fillWidth: true + Layout.fillHeight: true + textFormat: TextArea.PlainText + Layout.preferredWidth: parent.width - sendBtns.width - selectByMouse: true - Keys.onEnterPressed: { - chatsModel.sendMessage(txtData.text) - txtData.text = "" - } - Keys.onReturnPressed: { - chatsModel.sendMessage(txtData.text) - txtData.text = "" - } - background: Rectangle { - color: "#00000000" + id: txtData + text: "" + selectByMouse: true + topPadding: Theme.padding + leftPadding: 12 + rightPadding: Theme.padding + font.pixelSize: 14 + placeholderText: qsTr("Type a message...") + Keys.onEnterPressed: onEnter(event) + Keys.onReturnPressed: onEnter(event) + background: Rectangle { + color: "#00000000" + } } } @@ -50,14 +65,6 @@ Rectangle { } } - MouseArea { - id: mouseArea1 - anchors.rightMargin: 50 - anchors.fill: parent - onClicked: { - txtData.forceActiveFocus(Qt.MouseFocusReason) - } - } } /*##^## Designer { diff --git a/ui/shared/StyledTArea.qml b/ui/shared/StyledTArea.qml new file mode 100644 index 0000000000..3cc3076c7f --- /dev/null +++ b/ui/shared/StyledTArea.qml @@ -0,0 +1,7 @@ +import QtQuick 2.13 +import QtQuick.Controls 2.13 +import "../imports" + +TextArea { + font.family: Theme.fontRegular.name +}