After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 121904 - copy-paste of empty line
copy-paste of empty line
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
0.11.x
Other other
: Normal normal
: ---
Assigned To: Behdad Esfahbod
VTE Maintainers
Depends on:
Blocks:
 
 
Reported: 2003-09-10 13:57 UTC by Egmont Koblinger
Modified: 2006-07-11 00:52 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
Proposed patch (4.02 KB, patch)
2005-08-22 04:51 UTC, Chris Heath
none Details | Review

Description Egmont Koblinger 2003-09-10 13:57:34 UTC
When highlighting a part of the terminal, trailing spaces are usually
stripped and hence they are not put into the clipboard. Nice.

However if I mark an emtpy line (or a bigger region that contains an
empty line) then the clipboard will have plenty of space characters here
instead of nothing more than adjacent newline characters. This makes it
hard to copy-paste larger parts of texts: either I have to copy from
paragraph to paragraph, or remove these lots-of-spaces lines from the new
document.
Comment 1 Egmont Koblinger 2003-09-12 21:10:25 UTC
Oh, it's a vte bug.
Comment 2 Michele Baldessari 2005-07-29 20:54:10 UTC
Hi Egmont,

your comment does make some sense, but I really don't see a sane way to 
distinguish the case in which the user really wants those empty lines (think 
of a code snippet where the empy line makes it more readable or anything similar).

And I believe that the behaviour of copying exactly what was on the screen makes
more sense given a choice.

I'd say this is NOTABUG.

what do you think?
Comment 3 Egmont Koblinger 2005-07-31 08:11:13 UTC
Hi Michele,

You're right, mouse selection should copy exactly what is on the screen.
If I see empty lines, I want empty lines to be copied to the buffer, but that
is always how vte worked and works now, no problem with this. The problem was,
in older versions of vte, is plenty of extra unnecessary _space_ characters
added to the buffer if an empty line was selected.

This is gone now, as of vte 0.11.13, but there's another bug: if I copy a
region that contains only space characters (one or more spaces) then the
clipboard is cleared, these spaces are not put there.
Comment 4 Kjartan Maraas 2005-08-12 17:24:20 UTC
What does xterm do in this case? It's been said over and over that we should
emulate xterm behaviour as closely as possible...
Comment 5 Chris Heath 2005-08-21 21:11:52 UTC
Xterm copies the spaces, as one would expect.

In fact, xterm even allows you to select the spaces at the end of a line if they
were explicitly printed.  For example:
1. Run this command in xterm/g-t:  echo "hello"; echo "hello   "
2. Select both output lines and paste them in gedit.

Result: when done in xterm, the 3 extra spaces on the second line are preserved.
 When done in g-t, no spaces are copied at all.

And there's another related bug in g-t, which xterm gets right:
1. Run this command in xterm/g-t (assuming terminal width=80, and a UTF-8 locale):
  perl -e 'use open ":locale"; print "x" x 79, "\x{3042}\n"'
2. Select the whole output and paste into gedit.

Result: Both xterm and g-t insert a space after the 79 x's so that the entire
U+3042 (double-width Hiragana A) appears on the next line.  However, when you
select the output in g-t, the extra space is copied, whereas in xterm it is not
copied.
Comment 6 Chris Heath 2005-08-22 04:51:26 UTC
Created attachment 51087 [details] [review]
Proposed patch

This patch makes vte keep track of whether each cell is empty or not, and
changes the selection algorithm to use this information instead of looking for
spaces at ends of lines.  It fixes all the above-mentioned problems.
Comment 7 Egmont Koblinger 2005-08-22 09:33:11 UTC
Nice work, works perfectly for me, thanks!!! Someone please commit it :-)
I'll keep on using vte with this patch and will report immediately if I find
something wrong.
Comment 8 Egmont Koblinger 2005-08-23 13:27:50 UTC
Well, the patch (or other relevant parts of vte) is not perfect.

This bug is easily reproducible:

If a line contains some spaces at its end, then highlighting with a single
mouse click works okay, however, highlighting with double click (actually
one-and-a-half: click, raise, click and hold) is not okay, visually one more
space character is highlighted at the end of the line. For example, a typical
command typed using the TAB completion ends in one space, but if highlighted
with double click, two spaces are highlighted. (But only one is actually copied
to the clipboard.)

This one is hard to reproduce:

For lines ending with a space, rarely the double click selection method skips
the option to include that space but not the newline. E.g. skips the option
that is visually incorrectly displayed as described above. First only the text
part is highlighted and copied to the clipboard, but if I move the mouse to the
right, suddenly the whole line gets highlighted and the space and newline are
both put into the clipboard. The middle option (only the space, but not the
newline) is skipped.

This one is hard to reproduce too, it only happened to me 2 times:

Sometimes (rarely) the newline is missing from the clipboard. No, I don't mean
overlong lines that wrap to the next physical row, I'm just typing bash
commands of 40-50 characters in my 80 wide terminal. Still, very rarely, such
a line cannot be selected by a triple-click on its own, it gets highlighted
altogether with the next line just as if they were one long logical line, but
they aren't, as proven by a single-click selection which, after the text part
is highlighted, suddenly jumps to highlight the whole first line up to its end
instead of walking on the spaces one by one. No matter if this line is
selected by single, double or three clicks, the newline character is missing
from the clipboard.

I cannot systematically reproduce the two "rare" cases but I'll keep trying to.
One common thing in them is if one line misbehaves then that particular line
will still be misbehaving throughout the whole vte session, no matter how I
scroll or resize the window. If the terminal's content scrolls then the
location of this bug scrolls to, so it stays at the same text.
Comment 9 Behdad Esfahbod 2006-07-11 00:52:22 UTC
2006-07-10  Behdad Esfahbod  <behdad@gnome.org>

        Bug 121904 – copy-paste of empty line
        Bug 25290 – Small UI tweak to select-by-word (only select only letter
        at a time for non-word characters)
        Bug 339986 – Patch to select localized strings exactly

        * src/vte-private.h:
        * src/vte.c (_vte_terminal_set_default_attributes),
        (_vte_terminal_insert_char), (vte_terminal_is_word_char),
        (vte_same_class), (vte_terminal_get_text_range_maybe_wrapped),
        (vte_terminal_extend_selection):
        * src/vteseq.c (vte_sequence_handler_screen_alignment_test):
        Fix a bunch of selection-related issues.  We now recognize explicitly
        put space at the end of lines, and copy/paste it.  The other change is
        that non-wordchar characters are not grouped together.  Also fixes the
        fallback on Unicode properties that I added two commits ago.

Comment 10 Behdad Esfahbod 2006-07-11 00:52:53 UTC
I committed a drastically improved version of the patch.  It shouldn't have any of the issues you are reporting.