Skip to content

Commit

Permalink
fix: decode HTML entities when copying text to clipboard (fixes #1850)
Browse files Browse the repository at this point in the history
Currently, when using `Copy` in the context menu, the text will be
HTML escaped (e.g. `"` becomes `"`). Add a function to decode
HTML entities when copying to clipboard.

This PR fixes issue #1850.
  • Loading branch information
Integral-Tech committed Jan 9, 2025
1 parent 9df3bc1 commit e874268
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions resources/qml/MessageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Item {
text: qsTr("&Copy")
visible: messageContextMenuC.text

onTriggered: Clipboard.text = messageContextMenuC.text
onTriggered: Clipboard.setHtmlText(messageContextMenuC.text)
}
}
Component {
Expand Down Expand Up @@ -679,7 +679,7 @@ Item {
text: qsTr("&Copy")
visible: replyContextMenuC.text

onTriggered: Clipboard.text = replyContextMenuC.text
onTriggered: Clipboard.setHtmlText(replyContextMenuC.text)
}
}
Component {
Expand Down
7 changes: 7 additions & 0 deletions src/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Clipboard.h"

#include <QClipboard>
#include <QTextDocumentFragment>
#include <QGuiApplication>

Clipboard::Clipboard(QObject *parent)
Expand All @@ -19,6 +20,12 @@ Clipboard::setText(QString text)
QGuiApplication::clipboard()->setText(text);
}

void
Clipboard::setHtmlText(QString text)
{
setText(QTextDocumentFragment::fromHtml(text).toPlainText());
}

QString
Clipboard::text() const
{
Expand Down
1 change: 1 addition & 0 deletions src/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Clipboard : public QObject

QString text() const;
void setText(QString text_);
Q_INVOKABLE void setHtmlText(QString text_);
signals:
void textChanged();
};

0 comments on commit e874268

Please sign in to comment.