summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brüning <michael.bruning@qt.io>2020-07-03 01:16:07 +0200
committerMichael Brüning <michael.bruning@qt.io>2020-07-03 09:10:02 +0200
commit7b5cb517da57f76437872a891c07fffd1779b6a4 (patch)
treecdf0aaf9971cf17b9303ec8e1416d6262fb4025d
parentd9a062a876b9309bde6005695504147dcb174c87 (diff)
[macOS] Add utf-8 character set meta tag for HTML clipboard content
This prevents unicode characters from becoming garbled when pasting the clipboard content into an application that uses the HTML content instead of the text data. This mirrors the behavior of Chromium's clipboard adaptation for macOS Fixes: QTBUG-75391 Change-Id: I033819a2caf3410509e90c9bc38c9830d184149d Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
-rw-r--r--src/core/clipboard_qt.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/core/clipboard_qt.cpp b/src/core/clipboard_qt.cpp
index ef7a05299..c3b25ff63 100644
--- a/src/core/clipboard_qt.cpp
+++ b/src/core/clipboard_qt.cpp
@@ -143,7 +143,14 @@ void ClipboardQt::WriteText(const char *text_data, size_t text_len)
void ClipboardQt::WriteHTML(const char *markup_data, size_t markup_len, const char *url_data, size_t url_len)
{
- getUncommittedData()->setHtml(QString::fromUtf8(markup_data, markup_len));
+ QString markup_string = QString::fromUtf8(markup_data, markup_len);
+#if defined (Q_OS_MACOS)
+ // We need to prepend the charset on macOS to prevent garbled Unicode characters
+ // when pasting to certain applications (e.g. Notes, TextEdit)
+ // Mirrors the behavior in ui/base/clipboard/clipboard_mac.mm in Chromium.
+ markup_string.prepend(QLatin1String("<meta charset='utf-8'>"));
+#endif
+ getUncommittedData()->setHtml(markup_string);
}
void ClipboardQt::WriteRTF(const char *rtf_data, size_t data_len)