Ensure that text isn't formatted in context menu

This commit is contained in:
Tobias Fella
2022-07-09 23:01:13 +02:00
parent 27e660178e
commit 2bcd7118f4
5 changed files with 18 additions and 6 deletions

View File

@@ -25,12 +25,12 @@ TimelineContainer {
TapHandler { TapHandler {
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onTapped: openMessageContext(model, parent.selectedText) onTapped: openMessageContext(model, parent.selectedText, Controller.plainText(parent.textDocument))
} }
TapHandler { TapHandler {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onLongPressed: openMessageContext(model, parent.selectedText) onLongPressed: openMessageContext(model, parent.selectedText, Controller.plainText(parent.textDocument))
} }
} }
} }

View File

@@ -20,6 +20,7 @@ Loader {
property string formattedBody: "" property string formattedBody: ""
required property string source required property string source
property string selectedText: "" property string selectedText: ""
required property string plainMessage
property list<Kirigami.Action> nestedActions property list<Kirigami.Action> nestedActions
@@ -45,7 +46,7 @@ Loader {
Kirigami.Action { Kirigami.Action {
text: i18n("Copy") text: i18n("Copy")
icon.name: "edit-copy" icon.name: "edit-copy"
onTriggered: Clipboard.saveText(loadRoot.selectedText === "" ? loadRoot.message : loadRoot.selectedText) onTriggered: Clipboard.saveText(loadRoot.selectedText === "" ? loadRoot.plainMessage : loadRoot.selectedText)
}, },
Kirigami.Action { Kirigami.Action {
text: i18n("View Source") text: i18n("View Source")
@@ -111,7 +112,7 @@ Loader {
Instantiator { Instantiator {
model: WebShortcutModel { model: WebShortcutModel {
id: webshortcutmodel id: webshortcutmodel
selectedText: loadRoot.selectedText ? loadRoot.selectedText : loadRoot.message selectedText: loadRoot.selectedText ? loadRoot.selectedText : loadRoot.plainMessage
onOpenUrl: RoomManager.visitNonMatrix(url) onOpenUrl: RoomManager.visitNonMatrix(url)
} }
delegate: QQC2.MenuItem { delegate: QQC2.MenuItem {

View File

@@ -598,12 +598,13 @@ Kirigami.ScrollablePage {
file: file, file: file,
mimeType: event.mimeType, mimeType: event.mimeType,
progressInfo: event.progressInfo, progressInfo: event.progressInfo,
plainMessage: event.message,
}); });
contextMenu.open(); contextMenu.open();
} }
/// Open context menu for normal message /// Open context menu for normal message
function openMessageContext(event, selectedText) { function openMessageContext(event, selectedText, plainMessage) {
const contextMenu = messageDelegateContextMenu.createObject(page, { const contextMenu = messageDelegateContextMenu.createObject(page, {
selectedText: selectedText, selectedText: selectedText,
author: event.author, author: event.author,
@@ -611,7 +612,8 @@ Kirigami.ScrollablePage {
eventId: event.eventId, eventId: event.eventId,
formattedBody: event.formattedBody, formattedBody: event.formattedBody,
source: event.source, source: event.source,
eventType: event.eventType eventType: event.eventType,
plainMessage: plainMessage,
}); });
contextMenu.open(); contextMenu.open();
} }

View File

@@ -24,10 +24,12 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QPixmap> #include <QPixmap>
#include <QQuickItem> #include <QQuickItem>
#include <QQuickTextDocument>
#include <QQuickWindow> #include <QQuickWindow>
#include <QStandardPaths> #include <QStandardPaths>
#include <QStringBuilder> #include <QStringBuilder>
#include <QSysInfo> #include <QSysInfo>
#include <QTextDocument>
#include <QTimer> #include <QTimer>
#include <utility> #include <utility>
@@ -700,3 +702,8 @@ bool Controller::hasWindowSystem() const
return false; return false;
#endif #endif
} }
QString Controller::plainText(QQuickTextDocument *document) const
{
return document->textDocument()->toPlainText();
}

View File

@@ -21,6 +21,7 @@ class NeoChatRoom;
class NeoChatUser; class NeoChatUser;
class TrayIcon; class TrayIcon;
class QQuickWindow; class QQuickWindow;
class QQuickTextDocument;
namespace QKeychain namespace QKeychain
{ {
@@ -94,6 +95,7 @@ public:
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur); Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
Q_INVOKABLE void raiseWindow(QWindow *window); Q_INVOKABLE void raiseWindow(QWindow *window);
Q_INVOKABLE QString plainText(QQuickTextDocument *document) const;
private: private:
explicit Controller(QObject *parent = nullptr); explicit Controller(QObject *parent = nullptr);