diff --git a/TODO.md b/TODO.md index 8269061c..7bee0c59 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # TODO +- show "copy selection" when right clicking on image - make it not select messages when closing context menu - long-press-drag to select multiple messages on touch - drag to select on non-touch diff --git a/src/gui/Pages/Chat/ChatPage.qml b/src/gui/Pages/Chat/ChatPage.qml index b95bcc36..3a36b792 100644 --- a/src/gui/Pages/Chat/ChatPage.qml +++ b/src/gui/Pages/Chat/ChatPage.qml @@ -81,7 +81,7 @@ HColumnPage { Composer { id: composer - eventList: loadEventList ? eventListLoader.item : null + eventList: loadEventList ? eventListLoader.item.eventList : null visible: ! chat.roomInfo.left && ! chat.roomInfo.inviter_id } diff --git a/src/gui/Pages/Chat/Composer.qml b/src/gui/Pages/Chat/Composer.qml index 972d8b77..c2a53292 100644 --- a/src/gui/Pages/Chat/Composer.qml +++ b/src/gui/Pages/Chat/Composer.qml @@ -18,7 +18,7 @@ Rectangle { Layout.maximumHeight: pageLoader.height / 2 - property Item eventList + property HListView eventList property string indent: " " @@ -165,11 +165,6 @@ Rectangle { } } - // XXX - // area.onSelectedTextChanged: if (area.selectedText && eventList) { - // eventList.selectableLabelContainer.clearSelection() - // } - Component.onCompleted: { area.Keys.onReturnPressed.connect(ev => { ev.accepted = true @@ -207,16 +202,15 @@ Rectangle { }) area.Keys.onPressed.connect(ev => { - // XXX - // if (ev.matches(StandardKey.Copy) && - // eventList && - // eventList.selectableLabelContainer.joinedSelection - // ) { - // ev.accepted = true - // Clipboard.text = - // eventList.selectableLabelContainer.joinedSelection - // return - // } + if (ev.matches(StandardKey.Copy) && + ! area.selectedText && + eventList && + eventList.selectedCount) { + + ev.accepted = true + eventList.copySelectedDelegates() + return + } // FIXME: buggy // if (ev.modifiers === Qt.NoModifier && diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index 7df3f39c..3f14feea 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -162,8 +162,13 @@ HRowLayout { Layout.maximumWidth: eventContent.maxMessageWidth Layout.fillWidth: true - onSelectedTextChanged: - if (selectedText) eventList.delegateWithSelectedText = model.id + onSelectedTextChanged: if (selectedText) { + eventList.delegateWithSelectedText = model.id + eventList.selectedText = selectedText + } else if (eventList.delegateWithSelectedText === model.id) { + eventList.delegateWithSelectedText = "" + eventList.selectedText = "" + } Connections { target: eventList diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index af46db2e..7fa3c488 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -196,18 +196,7 @@ HColumnLayout { return } - if (eventContent.selectedText) { - Clipboard.text = eventContent.selectedText - return - } - - const contents = [] - - for (const model of eventList.getSortedCheckedDelegates()) { - contents.push(JSON.parse(model.source).body) - } - - Clipboard.text = contents.join("\n\n") + eventList.copySelectedDelegates() } } diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index efd764b5..3a8540be 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -3,6 +3,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 +import Clipboard 0.1 import "../../.." import "../../../Base" @@ -77,8 +78,24 @@ Rectangle { width < theme.chat.eventList.ownEventsOnRightUnderWidth property string delegateWithSelectedText: "" + property string selectedText: "" + function copySelectedDelegates() { + if (eventList.selectedText) { + Clipboard.text = eventList.selectedText + return + } + + const contents = [] + + for (const model of eventList.getSortedCheckedDelegates()) { + contents.push(JSON.parse(model.source).body) + } + + Clipboard.text = contents.join("\n\n") + } + function canCombine(item, itemAfter) { if (! item || ! itemAfter) return false