From 32fde57ba79588ad31becb9cb395a822e9674a63 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 1 Sep 2019 03:40:48 -0400 Subject: [PATCH] Make message display names selectable --- TODO.md | 1 - src/qml/Base/HSelectableLabel.qml | 4 +++- src/qml/Base/HSelectableLabelContainer.qml | 13 ++++++++----- src/qml/Chat/Timeline/EventContent.qml | 13 +++++++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 69d992c2..5b0a4d6f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,4 @@ - Message selection - - Copy names - Copy text with triple click, copy text + name + date with quadruple click - Copy to X11 selection - Make scroll wheel usable diff --git a/src/qml/Base/HSelectableLabel.qml b/src/qml/Base/HSelectableLabel.qml index 90b5b7df..cd4fcb0f 100644 --- a/src/qml/Base/HSelectableLabel.qml +++ b/src/qml/Base/HSelectableLabel.qml @@ -26,8 +26,10 @@ TextEdit { } + // 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. + property real index property HSelectableLabelContainer container - property int index function updateSelection() { diff --git a/src/qml/Base/HSelectableLabelContainer.qml b/src/qml/Base/HSelectableLabelContainer.qml index 1b2c5b3c..3644728e 100644 --- a/src/qml/Base/HSelectableLabelContainer.qml +++ b/src/qml/Base/HSelectableLabelContainer.qml @@ -11,10 +11,9 @@ FocusScope { property bool reversed: false readonly property bool dragging: pointHandler.active || dragHandler.active - // onDraggingChanged: print(dragging) property bool selecting: false - property int selectionStart: -1 - property int selectionEnd: -1 + property real selectionStart: -1 + property real selectionEnd: -1 property point selectionStartPosition: Qt.point(-1, -1) property point selectionEndPosition: Qt.point(-1, -1) property var selectedTexts: ({}) @@ -28,12 +27,16 @@ FocusScope { let toCopy = [] for (let key of Object.keys(selectedTexts).sort()) { - if (selectedTexts[key]) toCopy.push(selectedTexts[key]) + if (! selectedTexts[key]) continue + + // For some dumb reason, Object.keys convert the floats to strings + toCopy.push(Number.isInteger(parseFloat(key)) ? "\n\n" : "\n") + toCopy.push(selectedTexts[key]) } if (reversed) toCopy.reverse() - return toCopy.join("\n\n") + return toCopy.join("").trim() } readonly property alias dragPoint: dragHandler.centroid diff --git a/src/qml/Chat/Timeline/EventContent.qml b/src/qml/Chat/Timeline/EventContent.qml index 3faa1c8b..4c488693 100644 --- a/src/qml/Chat/Timeline/EventContent.qml +++ b/src/qml/Chat/Timeline/EventContent.qml @@ -46,19 +46,24 @@ Row { Column { anchors.fill: parent - HLabel { + HSelectableLabel { id: nameLabel width: parent.width visible: ! hideNameLine + container: selectableLabelContainer + + // This is +0.1 and content is +0 instead of the opposite, + // because the eventList is reversed + index: model.index + 0.1 text: Utils.coloredNameHtml(model.sender_name, model.sender_id) - textFormat: Text.StyledText - elide: Text.ElideRight + textFormat: Text.RichText + // elide: Text.ElideRight horizontalAlignment: onRight ? Text.AlignRight : Text.AlignLeft leftPadding: theme.spacing rightPadding: leftPadding - topPadding: theme.spacing / 2 * lineHeight + topPadding: theme.spacing / 2 } HSelectableLabel {