From 9936a7e2eec551fe8ffd06fc8989394c22910683 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 1 Sep 2019 06:56:03 -0400 Subject: [PATCH] Fix ctrl-c behavior --- src/qml/Base/HSelectableLabel.qml | 9 ----- src/qml/Base/HSelectableLabelContainer.qml | 2 +- src/qml/Chat/ChatSplitView.qml | 2 ++ src/qml/Chat/Composer.qml | 38 +++++++++++++++------- src/qml/Chat/Timeline/EventList.qml | 3 +- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/qml/Base/HSelectableLabel.qml b/src/qml/Base/HSelectableLabel.qml index a5a21c0e..38c61f65 100644 --- a/src/qml/Base/HSelectableLabel.qml +++ b/src/qml/Base/HSelectableLabel.qml @@ -18,15 +18,6 @@ TextEdit { onLinkActivated: Qt.openUrlExternally(link) - Keys.onPressed: ev => { - if (ev.matches(StandardKey.Copy)) { - ev.accepted = true - Utils.copyToClipboard(container.joinedSelection) - return - } - ev.accepted = false - } - // If index is a whole number, the label will get two \n before itself // in container.joinedSelection. If it's a decimal number, if gets one \n. diff --git a/src/qml/Base/HSelectableLabelContainer.qml b/src/qml/Base/HSelectableLabelContainer.qml index ea8c3894..2f22e445 100644 --- a/src/qml/Base/HSelectableLabelContainer.qml +++ b/src/qml/Base/HSelectableLabelContainer.qml @@ -2,7 +2,7 @@ import QtQuick 2.12 import "../utils.js" as Utils FocusScope { - onFocusChanged: if (! focus) clearSelection() + onSelectedTextsChanged: if (selectedTexts) composer.textArea.deselect() signal deselectAll() diff --git a/src/qml/Chat/ChatSplitView.qml b/src/qml/Chat/ChatSplitView.qml index 8fde3602..68bb9f61 100644 --- a/src/qml/Chat/ChatSplitView.qml +++ b/src/qml/Chat/ChatSplitView.qml @@ -13,6 +13,8 @@ HSplitView { Layout.fillWidth: true EventList { + id: eventList + // Avoid a certain binding loop Layout.minimumWidth: theme.minimumSupportedWidth Layout.fillWidth: true diff --git a/src/qml/Chat/Composer.qml b/src/qml/Chat/Composer.qml index 9cb806a9..eadaf75e 100644 --- a/src/qml/Chat/Composer.qml +++ b/src/qml/Chat/Composer.qml @@ -140,13 +140,17 @@ Rectangle { } } - Component.onCompleted: { - area.Keys.onReturnPressed.connect(event => { - event.accepted = true + area.onSelectedTextChanged: if (area.selectedText) { + eventList.selectableLabelContainer.clearSelection() + } - if (event.modifiers & Qt.ShiftModifier || - event.modifiers & Qt.ControlModifier || - event.modifiers & Qt.AltModifier) + Component.onCompleted: { + area.Keys.onReturnPressed.connect(ev => { + ev.accepted = true + + if (ev.modifiers & Qt.ShiftModifier || + ev.modifiers & Qt.ControlModifier || + ev.modifiers & Qt.AltModifier) { let indents = 0 let parts = lineText.split(indent) @@ -171,17 +175,27 @@ Rectangle { area.Keys.onEnterPressed.connect(area.Keys.onReturnPressed) - area.Keys.onTabPressed.connect(event => { - event.accepted = true + area.Keys.onTabPressed.connect(ev => { + ev.accepted = true textArea.insert(cursorPosition, indent) }) - area.Keys.onPressed.connect(event => { - if (event.modifiers == Qt.NoModifier && - event.key == Qt.Key_Backspace && + area.Keys.onPressed.connect(ev => { + if (ev.matches(StandardKey.Copy) && + eventList.selectableLabelContainer.joinedSelection + ) { + ev.accepted = true + Utils.copyToClipboard( + eventList.selectableLabelContainer.joinedSelection, + ) + return + } + + if (ev.modifiers == Qt.NoModifier && + ev.key == Qt.Key_Backspace && ! textArea.selectedText) { - event.accepted = true + ev.accepted = true textArea.remove( cursorPosition - deleteCharsOnBackspace, cursorPosition diff --git a/src/qml/Chat/Timeline/EventList.qml b/src/qml/Chat/Timeline/EventList.qml index 2426ba9c..9819bb8c 100644 --- a/src/qml/Chat/Timeline/EventList.qml +++ b/src/qml/Chat/Timeline/EventList.qml @@ -3,7 +3,8 @@ import "../../Base" import "../../utils.js" as Utils Rectangle { - property alias listView: eventList + property alias selectableLabelContainer: selectableLabelContainer + property alias eventList: eventList color: theme.chat.eventList.background