macOS: Better document plain-text code-path in QMacPasteboard::retrieveData
Due to PasteboardCopyItemFlavorData converting newlines to '\r' for some UTIs we have traditionally had to shortcut these UTIs via NSStringPboardType instead of the mime converters such as QMacPasteboardMimeUnicodeText. Let's explain this a bit better for future generations. Note that public.utf8-plain-text doesn't seem to have this problem anymore, but it's left in for now to not cause any regressions due to behavior change. Change-Id: I7dce80828865c6323ed308780b8ca07b7a3e7c17 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
4504d9ca31
commit
e6036cfc5a
@ -489,13 +489,12 @@ QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const
|
|||||||
QMacInternalPasteboardMime *c = mimes.at(mime);
|
QMacInternalPasteboardMime *c = mimes.at(mime);
|
||||||
QString c_flavor = c->flavorFor(format);
|
QString c_flavor = c->flavorFor(format);
|
||||||
if (!c_flavor.isEmpty()) {
|
if (!c_flavor.isEmpty()) {
|
||||||
// Handle text/plain a little differently. Try handling Unicode first.
|
// Converting via PasteboardCopyItemFlavorData below will for some UITs result
|
||||||
bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text")
|
// in newlines mapping to '\r' instead of '\n'. To work around this we shortcut
|
||||||
|| c_flavor == QLatin1String("public.utf8-plain-text"));
|
// the conversion via NSPasteboard's NSStringPboardType if possible.
|
||||||
if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) {
|
if (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text")
|
||||||
// Try to get the NSStringPboardType from NSPasteboard, newlines are mapped
|
|| c_flavor == QLatin1String("public.utf8-plain-text")
|
||||||
// correctly (as '\n') in this data. The 'public.utf16-plain-text' type
|
|| c_flavor == QLatin1String("public.utf16-plain-text")) {
|
||||||
// usually maps newlines to '\r' instead.
|
|
||||||
QString str = qt_mac_get_pasteboardString(paste);
|
QString str = qt_mac_get_pasteboardString(paste);
|
||||||
if (!str.isEmpty())
|
if (!str.isEmpty())
|
||||||
return str;
|
return str;
|
||||||
|
Loading…
Reference in New Issue
Block a user