Pasting text copied from Linux results in doubled lines (#7144)
text/plain;charset=utf-8 clipboard format. This results in double lines when pasting text copied from Linux to Windows because the Windows client converts line endings and expects only LF. Co-authored-by: Pedro Navarro <pnavarro@netflix.com>
This commit is contained in:
parent
35d7d2754d
commit
3784e42245
3 changed files with 32 additions and 5 deletions
|
|
@ -83,9 +83,9 @@ XWindowsClipboard::XWindowsClipboard(Display* display,
|
|||
"application/x-moz-nativehtml"));
|
||||
m_converters.push_back(new XWindowsClipboardBMPConverter(m_display));
|
||||
m_converters.push_back(new XWindowsClipboardUTF8Converter(m_display,
|
||||
"text/plain;charset=UTF-8"));
|
||||
"text/plain;charset=UTF-8", true));
|
||||
m_converters.push_back(new XWindowsClipboardUTF8Converter(m_display,
|
||||
"text/plain;charset=utf-8"));
|
||||
"text/plain;charset=utf-8", true));
|
||||
m_converters.push_back(new XWindowsClipboardUTF8Converter(m_display,
|
||||
"UTF8_STRING"));
|
||||
m_converters.push_back(new XWindowsClipboardUCS2Converter(m_display,
|
||||
|
|
|
|||
|
|
@ -18,13 +18,15 @@
|
|||
|
||||
#include "platform/XWindowsClipboardUTF8Converter.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// XWindowsClipboardUTF8Converter
|
||||
//
|
||||
|
||||
XWindowsClipboardUTF8Converter::XWindowsClipboardUTF8Converter(
|
||||
Display* display, const char* name) :
|
||||
m_atom(XInternAtom(display, name, False))
|
||||
Display* display, const char* name, bool normalize) :
|
||||
m_atom(XInternAtom(display, name, False)), m_normalize(normalize)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
|
@ -52,6 +54,13 @@ XWindowsClipboardUTF8Converter::getDataSize() const
|
|||
return 8;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
isCR(char ch)
|
||||
{
|
||||
return (ch == '\r');
|
||||
}
|
||||
|
||||
String
|
||||
XWindowsClipboardUTF8Converter::fromIClipboard(const String& data) const
|
||||
{
|
||||
|
|
@ -61,5 +70,22 @@ XWindowsClipboardUTF8Converter::fromIClipboard(const String& data) const
|
|||
String
|
||||
XWindowsClipboardUTF8Converter::toIClipboard(const String& data) const
|
||||
{
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1547595
|
||||
// GTK normalizes the clipboard's line endings to CRLF (\r\n) internally.
|
||||
// When sending the raw data to other systems, like Windows, where \n is
|
||||
// converted to \r\n we end up with \r\r\n, resulting in double lines when
|
||||
// pasting.
|
||||
//
|
||||
// This seems to happen only when the clipboard format is
|
||||
// text/plain;charset=utf8 and not when it's UTF8_STRING.
|
||||
// When normalize clipboard is set, any \r present in the string is removed
|
||||
|
||||
if (m_normalize) {
|
||||
String copy = data;
|
||||
|
||||
copy.erase(std::remove_if(copy.begin(), copy.end(), isCR), copy.end());
|
||||
return copy;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public:
|
|||
/*!
|
||||
\c name is converted to an atom and that is reported by getAtom().
|
||||
*/
|
||||
XWindowsClipboardUTF8Converter(Display* display, const char* name);
|
||||
XWindowsClipboardUTF8Converter(Display* display, const char* name, bool normalize = false);
|
||||
virtual ~XWindowsClipboardUTF8Converter();
|
||||
|
||||
// IXWindowsClipboardConverter overrides
|
||||
|
|
@ -39,4 +39,5 @@ public:
|
|||
|
||||
private:
|
||||
Atom m_atom;
|
||||
bool m_normalize;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue