Chop a possible trailing \0 from retrieved text
Some apps (e.g. Chromium) explicitly append a \0 to the text they transmit through the clipboard. Remove that one, when we retrieve the text, so it doesn't become part of the text we're pasting. This was e.g. visible when pasting from chromium to the textedit example. Change-Id: I9445319e6e5ef304a364e14f794b16557a3cc919 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
parent
a779d68256
commit
dcc605beb6
@ -160,9 +160,10 @@ QVector<xcb_atom_t> QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, con
|
||||
return atoms;
|
||||
}
|
||||
|
||||
QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format,
|
||||
QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &d, const QString &format,
|
||||
QVariant::Type requestedType, const QByteArray &encoding)
|
||||
{
|
||||
QByteArray data = d;
|
||||
QString atomName = mimeAtomToString(connection, a);
|
||||
// qDebug() << "mimeConvertDataToFormat" << format << atomName << data;
|
||||
|
||||
@ -182,8 +183,11 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
|
||||
// special cases for string types
|
||||
if (format == QLatin1String("text/plain")) {
|
||||
if (a == connection->atom(QXcbAtom::UTF8_STRING))
|
||||
if (data.endsWith('\0'))
|
||||
data.chop(1);
|
||||
if (a == connection->atom(QXcbAtom::UTF8_STRING)) {
|
||||
return QString::fromUtf8(data);
|
||||
}
|
||||
if (a == XCB_ATOM_STRING ||
|
||||
a == connection->atom(QXcbAtom::TEXT))
|
||||
return QString::fromLatin1(data);
|
||||
@ -221,6 +225,9 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
}
|
||||
}
|
||||
}
|
||||
// 8 byte encoding, remove a possible 0 at the end
|
||||
if (data.endsWith('\0'))
|
||||
data.chop(1);
|
||||
}
|
||||
|
||||
if (atomName == format)
|
||||
|
Loading…
Reference in New Issue
Block a user