Skip to content

Commit 21a49fe

Browse files
committed
[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 <[email protected]> (cherry picked from commit 7b5cb51)
1 parent b30c081 commit 21a49fe

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/clipboard_qt.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,14 @@ void ClipboardQt::WriteText(const char* text_data, size_t text_len)
235235

236236
void ClipboardQt::WriteHTML(const char* markup_data, size_t markup_len, const char* url_data, size_t url_len)
237237
{
238-
getUncommittedData()->setHtml(QString::fromUtf8(markup_data, markup_len));
238+
QString markup_string = QString::fromUtf8(markup_data, markup_len);
239+
#if defined (Q_OS_MACOS)
240+
// We need to prepend the charset on macOS to prevent garbled Unicode characters
241+
// when pasting to certain applications (e.g. Notes, TextEdit)
242+
// Mirrors the behavior in ui/base/clipboard/clipboard_mac.mm in Chromium.
243+
markup_string.prepend(QLatin1String("<meta charset='utf-8'>"));
244+
#endif
245+
getUncommittedData()->setHtml(markup_string);
239246
}
240247

241248
void ClipboardQt::WriteRTF(const char* rtf_data, size_t data_len)

0 commit comments

Comments
 (0)