From b70f73c7d6ce2b1f09464b4b3a4bcc7a6f804957 Mon Sep 17 00:00:00 2001 From: Eren Karakas Date: Wed, 6 Nov 2024 21:09:58 +0000 Subject: [PATCH] Make send message and insert newline shortcuts configurable Currently both Enter and Ctrl+Enter send the message in ChatBar on desktop. This might be unexpected behavior to users coming from other chat applications (eg. WhatsApp, Telegram, Element) as those send with Enter only by default. They allow changing send to Ctrl+Enter in settings and other option is used to insert a newline. BUG: 476758 --- src/chatbar/ChatBar.qml | 10 ++++++---- src/neochatconfig.kcfg | 12 ++++++++++++ src/settings/NeoChatGeneralPage.qml | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/chatbar/ChatBar.qml b/src/chatbar/ChatBar.qml index 7220d30a0..1161528b9 100644 --- a/src/chatbar/ChatBar.qml +++ b/src/chatbar/ChatBar.qml @@ -251,20 +251,22 @@ QQC2.Control { } } Keys.onEnterPressed: event => { + const controlIsPressed = event.modifiers & Qt.ControlModifier; if (completionMenu.visible) { completionMenu.complete(); - } else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile) { + } else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile || NeoChatConfig.sendMessageWith === 1 && !controlIsPressed || NeoChatConfig.sendMessageWith === 0 && controlIsPressed) { textField.insert(cursorPosition, "\n"); - } else { + } else if (NeoChatConfig.sendMessageWith === 0 && !controlIsPressed || NeoChatConfig.sendMessageWith === 1 && controlIsPressed) { _private.postMessage(); } } Keys.onReturnPressed: event => { + const controlIsPressed = event.modifiers & Qt.ControlModifier; if (completionMenu.visible) { completionMenu.complete(); - } else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile) { + } else if (event.modifiers & Qt.ShiftModifier || Kirigami.Settings.isMobile || NeoChatConfig.sendMessageWith === 1 && !controlIsPressed || NeoChatConfig.sendMessageWith === 0 && controlIsPressed) { textField.insert(cursorPosition, "\n"); - } else { + } else if (NeoChatConfig.sendMessageWith === 0 && !controlIsPressed || NeoChatConfig.sendMessageWith === 1 && controlIsPressed) { _private.postMessage(); } } diff --git a/src/neochatconfig.kcfg b/src/neochatconfig.kcfg index b82e57d9a..867e4dfcc 100644 --- a/src/neochatconfig.kcfg +++ b/src/neochatconfig.kcfg @@ -27,6 +27,18 @@ false + + + + + + + + + + Enter + + true diff --git a/src/settings/NeoChatGeneralPage.qml b/src/settings/NeoChatGeneralPage.qml index d58ad9ffd..c38db8601 100644 --- a/src/settings/NeoChatGeneralPage.qml +++ b/src/settings/NeoChatGeneralPage.qml @@ -199,6 +199,32 @@ FormCard.FormCardPage { title: i18nc("Chat Editor", "Editor") } FormCard.FormCard { + FormCard.FormRadioDelegate { + text: i18nc("@option:radio", "Send messages with Enter") + checked: NeoChatConfig.sendMessageWith === 0 + visible: !Kirigami.Settings.isMobile + enabled: !NeoChatConfig.isSendMessageWithImmutable + onToggled: { + NeoChatConfig.sendMessageWith = 0 + NeoChatConfig.save() + } + } + FormCard.FormRadioDelegate { + id: sendWithEnterRadio + text: i18nc("@option:radio", "Send messages with Ctrl+Enter") + checked: NeoChatConfig.sendMessageWith === 1 + visible: !Kirigami.Settings.isMobile + enabled: !NeoChatConfig.isSendMessageWithImmutable + onToggled: { + NeoChatConfig.sendMessageWith = 1 + NeoChatConfig.save() + } + } + FormCard.FormDelegateSeparator { + visible: !Kirigami.Settings.isMobile + above: sendWithEnterRadio + below: quickEditCheckbox + } FormCard.FormCheckDelegate { id: quickEditCheckbox text: i18n("Use s/text/replacement syntax to edit your last message")