Bug 421480 - Pasting multiline text from Firefox results in double new lines between each text block
Summary: Pasting multiline text from Firefox results in double new lines between each ...
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: copy-paste (show other bugs)
Version: 20.04.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
: 423201 424130 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-05-13 19:12 UTC by Henrik Hudson
Modified: 2020-07-12 19:25 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.04.3
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Hudson 2020-05-13 19:12:01 UTC
Ultimately, this boils down to an issue with GTK3 and how it works, but wondering why KDE has been exposing this issue worse and worse in the last 3 months or so months. According to the GTK thread this functionality hasn't changed in years.

Specifically, when copy / pasting from a Firefox form field or other blocks of text and pasting to a Konsole vim window I get extra lines between everything. This is because GTK is adding '\r\n' to everything. Roughly 3 months ago this wasn't an issue, but then I started getting 'Filter' popups in Konsole when pasting into vim about "Other Unprintable Characters" and would I like to remove them. I would click "Remove" and all was good. As of a system update from a few days ago I stopped getting that pop-up and now when pasting into Konsole I just get extra spaces. 

If I paste into Kate first and then copy / paste out of Kate it's fine, so Kate is doing some cleanup. Would it be possible to move that "cleanup" closer to the KDE "core"?

How can I re-enable that pop-up to strip the unprintable characters or just make it automatic? I can't find it as an option in 'Konsole' or 'Klipper'. 

Gnome team has pretty much said "this is how it works since forever" and it's a won't fix until GTK4.


For reference:
https://bugzilla.mozilla.org/show_bug.cgi?id=1547595
https://bugzilla.mozilla.org/show_bug.cgi?id=1572104
https://gitlab.gnome.org/GNOME/gtk/issues/2307



STEPS TO REPRODUCE
1. Copy a block of text from a form field in Firefox (current release)
2. paste into a Konsole vim / nano editor window


OBSERVED RESULT
Get an extra space between every line

EXPECTED RESULT
No extra spaces

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Arch Linux - X11 with AMD GPU
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.70.0
Qt Version: 5.14.2

ADDITIONAL INFORMATION
Comment 1 outloudvi 2020-06-13 08:24:52 UTC
Can confirm and reproduce at Arch Linux w/ Plasma 5.19.0, Frameworks 5.70.0 and Qt 5.15.0.
Comment 2 Ahmad Samir 2020-06-14 09:50:15 UTC
Proposed fix https://invent.kde.org/utilities/konsole/-/merge_requests/118
Comment 3 Ahmad Samir 2020-06-15 20:33:06 UTC
Git commit a1022442dc2f59321976fd3456ad97c61300d1f2 by Ahmad Samir.
Committed on 15/06/2020 at 20:29.
Pushed by ahmadsamir into branch 'master'.

Don't add extra newlines when pasting from GTK applications

Due to some internal handling in GTK itself, we end up with text copied
from Firefox where a newline is represented as CRLF (\r\n); since the
doPaste() method replaces each \n with \r, we ended up with \r\r, which
ultimately led to extra newlines in the pasted code. To fix the issue
simply detect the CRLF case and replace each \r\n with \r.

To test, copy some multiline text from Firefox, open vim in konsole and
paste, you end up with two newlines between each block of text. Compare the
results after applying this patch
FIXED-IN: 20.08

M  +4    -0    src/TerminalDisplay.cpp

https://invent.kde.org/utilities/konsole/commit/a1022442dc2f59321976fd3456ad97c61300d1f2
Comment 4 Ahmad Samir 2020-06-19 01:34:57 UTC
*** Bug 423201 has been marked as a duplicate of this bug. ***
Comment 5 Ulrich Norbisrath 2020-06-19 11:43:03 UTC
As you see in my bug report Bug 423201 at the "xclip -o|hexdump" output, I sometimes get 0a0d in the clipboard which would be the reverse case of what is fixed here: linefeed and then carriage return, so your fix would actually not solve that issue. Maybe posting to vim works (but it should actually not either), but posting directly a set of sample commands (like the multiple echo block from reddit I mention) into Konsole will still create the unexpected results.

Shouldn't we also detect the \n\r case and replace that with a single \r?
This reverse \n\r seem to only happen when you turn on "synchronize contents of the clipboard and the selection" and really make a copy (ctrl-c) of your selection in Firefox. Shall I re-open my original bug or file one for klipper? I still think it would be an easy fix in the terminal itself, again it only influences konsole - all other terminals I tested can cope even with the reverse lfcr.
Comment 6 Ahmad Samir 2020-06-19 12:08:50 UTC
I'll reopen the other bug so that it's not forgotten, and then we can investigate  further whether it's the same issue or a different one.

Interesting about the \n\r (it makes sense to also replace \n\r with \r... but better look at klipper code first). Thanks for persisting with the report (I missed the \n\r bit, sorry about that).
Comment 7 Kurt Hindenburg 2020-06-19 14:51:25 UTC
Git commit 6b6a1e552492a25217cded1d83c25a652e5b249a by Kurt Hindenburg, on behalf of Ahmad Samir.
Committed on 19/06/2020 at 14:49.
Pushed by hindenburg into branch 'release/20.04'.

Don't add extra newlines when pasting from GTK applications

Due to some internal handling in GTK itself, we end up with text copied
from Firefox where a newline is represented as CRLF (\r\n); since the
doPaste() method replaces each \n with \r, we ended up with \r\r, which
ultimately led to extra newlines in the pasted code. To fix the issue
simply detect the CRLF case and replace each \r\n with \r.

To test, copy some multiline text from Firefox, open vim in konsole and
paste, you end up with two newlines between each block of text. Compare the
results after applying this patch
FIXED-IN: 20.04.3
(cherry picked from commit a1022442dc2f59321976fd3456ad97c61300d1f2)

M  +4    -0    src/TerminalDisplay.cpp

https://invent.kde.org/utilities/konsole/commit/6b6a1e552492a25217cded1d83c25a652e5b249a
Comment 8 Ahmad Samir 2020-06-20 18:12:24 UTC
*** Bug 423201 has been marked as a duplicate of this bug. ***
Comment 9 Ahmad Samir 2020-07-12 19:25:40 UTC
*** Bug 424130 has been marked as a duplicate of this bug. ***