From 21a49fe1bdfdf78c464a2fad89113d30247f0c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Fri, 3 Jul 2020 01:16:07 +0200 Subject: [macOS] Add utf-8 character set meta tag for HTML clipboard content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 7b5cb517da57f76437872a891c07fffd1779b6a4) --- src/core/clipboard_qt.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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("")); +#endif + getUncommittedData()->setHtml(markup_string); } void ClipboardQt::WriteRTF(const char* rtf_data, size_t data_len) -- cgit v1.2.3