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-06 10:04:24 +0200
commit21a49fe1bdfdf78c464a2fad89113d30247f0c34 (patch)
treedb4956b02a8a8cda0746e712444285422f614162
parentb30c0815fbdb29de8150c661fe9c27b9d4d68f7e (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> (cherry picked from commit 7b5cb517da57f76437872a891c07fffd1779b6a4)
-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 44756bdfe..c3724d409 100644
--- a/src/core/clipboard_qt.cpp
+++ b/src/core/clipboard_qt.cpp
@@ -235,7 +235,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)