Allow copying messages via right click

fixes #291
This commit is contained in:
Nicolas Werner 2021-04-29 23:38:45 +02:00
parent 9ab1dc253e
commit 2d678bdcf6
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 17 additions and 4 deletions

View file

@ -117,7 +117,7 @@ ScrollView {
image: ":/icons/icons/ui/vertical-ellipsis.png"
ToolTip.visible: hovered
ToolTip.text: qsTr("Options")
onClicked: messageContextMenu.show(row.model.id, row.model.type, row.model.isEncrypted, row.model.isEditable, "", optionsButton)
onClicked: messageContextMenu.show(row.model.id, row.model.type, row.model.isEncrypted, row.model.isEditable, "", row.model.body, optionsButton)
}
}

View file

@ -28,12 +28,12 @@ Item {
TapHandler {
acceptedButtons: Qt.RightButton
onSingleTapped: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink)
onSingleTapped: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink, contentItem.child.copyText)
gesturePolicy: TapHandler.ReleaseWithinBounds
}
TapHandler {
onLongPressed: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink)
onLongPressed: messageContextMenu.show(model.id, model.type, model.isEncrypted, model.isEditable, contentItem.child.hoveredLink, contentItem.child.copyText)
onDoubleTapped: chat.model.reply = model.id
gesturePolicy: TapHandler.ReleaseWithinBounds
}

View file

@ -93,15 +93,20 @@ Page {
property string eventId
property string link
property string text
property int eventType
property bool isEncrypted
property bool isEditable
function show(eventId_, eventType_, isEncrypted_, isEditable_, link_, showAt_) {
function show(eventId_, eventType_, isEncrypted_, isEditable_, link_, text_, showAt_) {
eventId = eventId_;
eventType = eventType_;
isEncrypted = isEncrypted_;
isEditable = isEditable_;
if (text_)
text = text_;
else
text = "";
if (link_)
link = link_;
else
@ -112,6 +117,13 @@ Page {
open();
}
Platform.MenuItem {
visible: messageContextMenu.text
enabled: visible
text: qsTr("Copy")
onTriggered: Clipboard.text = messageContextMenu.text
}
Platform.MenuItem {
visible: messageContextMenu.link
enabled: visible

View file

@ -7,6 +7,7 @@ import im.nheko 1.0
MatrixText {
property string formatted: model.data.formattedBody
property string copyText: selectedText ? getText(selectionStart, selectionEnd) : model.data.body
text: "<style type=\"text/css\">a { color:" + colors.link + ";}\ncode { background-color: " + colors.alternateBase + ";}</style>" + formatted.replace("<pre>", "<pre style='white-space: pre-wrap; background-color: " + colors.alternateBase + "'>")
width: parent ? parent.width : undefined