Make message display names selectable

This commit is contained in:
miruka 2019-09-01 03:40:48 -04:00
parent b610a404af
commit 32fde57ba7
4 changed files with 20 additions and 11 deletions

View File

@ -1,5 +1,4 @@
- Message selection - Message selection
- Copy names
- Copy text with triple click, copy text + name + date with quadruple click - Copy text with triple click, copy text + name + date with quadruple click
- Copy to X11 selection - Copy to X11 selection
- Make scroll wheel usable - Make scroll wheel usable

View File

@ -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 HSelectableLabelContainer container
property int index
function updateSelection() { function updateSelection() {

View File

@ -11,10 +11,9 @@ FocusScope {
property bool reversed: false property bool reversed: false
readonly property bool dragging: pointHandler.active || dragHandler.active readonly property bool dragging: pointHandler.active || dragHandler.active
// onDraggingChanged: print(dragging)
property bool selecting: false property bool selecting: false
property int selectionStart: -1 property real selectionStart: -1
property int selectionEnd: -1 property real selectionEnd: -1
property point selectionStartPosition: Qt.point(-1, -1) property point selectionStartPosition: Qt.point(-1, -1)
property point selectionEndPosition: Qt.point(-1, -1) property point selectionEndPosition: Qt.point(-1, -1)
property var selectedTexts: ({}) property var selectedTexts: ({})
@ -28,12 +27,16 @@ FocusScope {
let toCopy = [] let toCopy = []
for (let key of Object.keys(selectedTexts).sort()) { 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() if (reversed) toCopy.reverse()
return toCopy.join("\n\n") return toCopy.join("").trim()
} }
readonly property alias dragPoint: dragHandler.centroid readonly property alias dragPoint: dragHandler.centroid

View File

@ -46,19 +46,24 @@ Row {
Column { Column {
anchors.fill: parent anchors.fill: parent
HLabel { HSelectableLabel {
id: nameLabel id: nameLabel
width: parent.width width: parent.width
visible: ! hideNameLine 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) text: Utils.coloredNameHtml(model.sender_name, model.sender_id)
textFormat: Text.StyledText textFormat: Text.RichText
elide: Text.ElideRight // elide: Text.ElideRight
horizontalAlignment: onRight ? Text.AlignRight : Text.AlignLeft horizontalAlignment: onRight ? Text.AlignRight : Text.AlignLeft
leftPadding: theme.spacing leftPadding: theme.spacing
rightPadding: leftPadding rightPadding: leftPadding
topPadding: theme.spacing / 2 * lineHeight topPadding: theme.spacing / 2
} }
HSelectableLabel { HSelectableLabel {