Bug 2479962

Summary: double-click selection in a line spanning several display lines in xterm is in effect in the first of the lines
Product: [Fedora] Fedora Reporter: Albert Flügel <af>
Component: xtermAssignee: Tomas Korbar <tkorbar>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 44CC: dickey, tkorbar
Target Milestone: ---Keywords: Desktop, Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
URL: https://nc.getwings.eu/nextcloud/index.php/s/MgPMZ7GJnQQBNwT
Whiteboard:
Fixed In Version: Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Patch reverting a change that caused the vertical offset when double-clicking
none
Further patch for xterm-411 fixing more issues in the 2Click regex context none

Description Albert Flügel 2026-05-19 19:45:08 UTC
This is a very creative bug. I really wonder, how such things can be introduced accidentially: If a logical line spans several displayed lines in xterm and i double-click a word not in the first of the displayed lines, the selection is effective in the first displayed line nonetheless. When you look at the window-shot in the URL, you see the selection. Unfortunately the mouse-pointer is not visible, but i can tell you, that it was positioned over the /usr/ 5 lines below. It could have been also on the /usr 4 lines below or on the -sandboxReporter, the selection is always in the first displayed line.

Reproducible: Always

Steps to Reproduce:
1. start xterm
2. let xterm display some stuff that is longer than a line e.g. ps -ewwf
3. double-click on a part of the not-first line of a logical line spanning several displayed lines
Actual Results:
not the part, the mouse is over, is selected, but something above

Expected Results:
The part, where the mouse is over, is selected

Additional Information:
When i click and drag, the selection is correct i.e. not effective in another area. It happens only on double-click. Selecting the entire line with triple-click is also correct.

Comment 1 Thomas E. Dickey 2026-05-19 20:03:24 UTC
From the description, that's working as designed (for a very long time).
Quoting from the manpage

https://invisible-island.net/xterm/manpage/xterm.html#h3-Selection-Functions

            Multiple-click  is determined by the time from button up to button
            down, so you can change the selection unit  in  the  middle  of  a
            selection.  Logical words and lines selected by double- or triple-
            clicking  may  wrap across more than one screen line if lines were
            wrapped by xterm itself rather than by the application running  in
            the  window.   If  the  key/button  bindings  specify  that  an  X
            selection is to be  made,  xterm  will  leave  the  selected  text
            highlighted for as long as it is the selection owner.

Comment 2 Thomas E. Dickey 2026-05-19 20:06:17 UTC
If I'm misreading it, the actual version number helps, and of course a screenshot.

Comment 3 Thomas E. Dickey 2026-05-19 20:11:32 UTC
I see a screenshot, and will see if I can reproduce the effect.

Comment 4 Thomas E. Dickey 2026-05-19 20:45:04 UTC
hmm - the screenshot is consistent with xterm getting mouse events on the first line.
But you're saying that the mouse pointer could be on "any" part of the wrapped line.

So an explanation in terms of broken mouse coordinates doesn't fit.
(If my reading about "any" is incorrect, then this would fit).

I don't have a Fedora 44 at the moment, but have rawhide (I thought it would be close enough,
since it's patch #410).  But checking

https://packages.fedoraproject.org/pkgs/xterm/xterm/

it says Fedora 44 has #406.  I don't see anything to remind me in the changelog,
and I have a #406 (on Debian), which in a quick check doesn't misbehave in this way.

I checked my rawhide #410 on its desktop, and Debian #406 on XQuartz.
Mouse coordinate problems are more likely in the former, but I generally
don't see _those_ since the VM doesn't have hardware acceleration :-)

Comment 5 Thomas E. Dickey 2026-05-19 23:19:59 UTC
As an afterthought, it would be possible for some shell program to catch a single mouse click
and move it to that position, by using reverse-wraparound followed by left-cursor with a
large parameter, and then (using the column from the mouse click) back to the right.
That's unlikely (I think) but people using zsh for instance have a lot of odd add-ons.

I'll probably install a Fedora 44 "soon" (I have 42, 43 and rawhide, intending to drop 42.

Comment 6 Albert Flügel 2026-05-22 10:59:21 UTC
Thank you for explaining the multi-click behaviour of xterm. But frankly i know this. I'm using xterm nearly every day since about 1993, after cmdtool and shelltool on SunOS openlook and iirc termtool on sunview had been retired.
Interesting observation: I have an Fedora 42 here and there the effect is not visible locally. When i ssh to a system with Fedora 44 and start an xterm with Display-redirection to the local fedora 42 display (wayland), the effect is there, so it is definitely the xterm on Fedora 44 and nothing im terms of the shell. It does not matter, if a tcsh or bash is running in the xterm.
Ok, right, you deserve a version (sorry i was tired after work, what in the IT area is a mere bug-hunting and workarounding today): xterm-406-1.fc44.x86_64
If it was not clear enough: The 2nd section of this post spans nearly 3 lines in the text area in my case. You might resize your browser window to achieve this. Now assume you double-click the last word "xterm" and the word "with" 2 display lines above is selected.

Comment 7 Thomas E. Dickey 2026-05-23 18:53:14 UTC
I was using Apollo back then, and only recall xterm from sometime in 1988-1994 as a graphical thing in SR10.4 that didn't behave as nicely as Apollo's "pad" windows.  SR10.4 came out in March 1992, so I must be recalling from the last couple of years in that range.  I see some mention here of xterm

https://web-docs.gsi.de/~kraemer/COLLECTION/www.zepa.net/apollo/Apollo-FAQ.html

I installed Fedora 44, and don't see this problem.  However, there's an area where I wouldn't see it.
I'm using Parallels (on a MacMini), and sense that there's some lack of support for hardware acceleration.
(Ditto for VirtualBox).  I might see some acceleration bugs with VMWare (assuming that's the root cause).

If that's the answer, I suppose it works something like this: as xterm writes long lines which wrap,
it does the scrolling by shifting the window up -- which is a graphical operation that some clever
person might optimize in some obscure manner.  So... the first row of a wrapped line happens to not
follow some special case of writing to the end of the line and shifting.

If you do a repaint of the screen (control left mouse "Redraw Window"), that odd behavior
might just go away because the boundary conditions for the text all are discarded (no shifting, etc).

Comment 8 Albert Flügel 2026-05-28 19:18:17 UTC
Interesting. Apollo/Aegis i was using in 1986 at Siemens as an intern and unless my memory is romanticizing it, the terminal window was the most mature one i had to do with. It was never scrambled, history recall was always doing, what i expected, i was never wondering, wtf it is doing now

Regarding our xterm issue: i installed xterm-401-2.fc43, then xterm-397-1.fc42 on fc44 and found, that 401 already has the issue. However, 397 is working flawlessly on fc44. I looked through the changelog and there are 2 points, i'd consider candidates for the cause:
* adjust reported window-position by the shell window's border with ... (patch #401)
* revise a limit-check in selection to fix a regression in patch #398 (Debian #1105738) (patch #398)

I'm on vacation now for a week and will experiment when i'm back.

Comment 9 Albert Flügel 2026-06-26 07:45:57 UTC
Created attachment 2146711 [details]
Patch reverting a change that caused the vertical offset when double-clicking

This diff reverts the modification causing the vertical offset during double clicks. However, it introduces a horizontal offset in some cases. My guess is, that this modification was made to fix the horizontal offset, but introduced selecting always in the first part of a wrapped line.
So this is not a complete fix of the biased double-click selection. When i find leisure and muse, i'll try to work out a real fix.

Comment 10 Thomas E. Dickey 2026-06-28 14:25:33 UTC
thanks.  I'm in the middle of a larger change, which hasn't modified this function.
So... I'll try to dig into the root cause for this when I'm done.

Comment 11 Thomas E. Dickey 2026-06-28 14:30:08 UTC
fwiw, my checkin comment for this says it was to fix a potential overflow/underflow.
and reading the diff, it looks as if the comparison against zero is backwards.

Comment 12 Albert Flügel 2026-10-09 13:58:32 UTC
Now i found out, that the issue happens only, if the resource on2Clicks is set to some regex e.g.
XTerm*on2Clicks:       regex [-a-zA-Z0-9_]+

Comment 13 Albert Flügel 2026-10-09 18:46:56 UTC
Created attachment 2160564 [details]
Further patch for xterm-411 fixing more issues in the 2Click regex context

I've noticed, that the basic issue was fixed in xterm 411. Nonetheless there were still things not working as expected with 2click and regex:
* With every wrap of a line there is an additional offset 1, that the double-click selection is in effect towards the left
* Double click in the first and last displayed line mostly do not work, when they are wrapped lines to the outside of the inner part of xterm

These things are fixed with the attached patch against 411

Comment 14 Thomas E. Dickey 2026-10-11 22:11:34 UTC
hmm.  There are two parts to the patch:
a) something that computes an offset by searching up.
b) changing the order of evaluation for updating 'rows'

The (a) part doesn't seem to work as I understand what you're doing.
The charSeen string is essentially the 8-bit character equivalent of
the whole line.  So strlen() is returning 80 columns even when only
part of the line would match the regex.  (If you intend getting the
line-length, just MaxCols(screen) does that). Row 0, by the way, is the
top line of the visible display; searching backward from that goes
into the scrollback which is shown if panning up.

==> MaxCols(screen) works for me.

The (b) part could account for the "additional offset 1", but in
experimenting with/without the patch, I haven't seen a difference.

Comment 15 Albert Flügel 2026-10-12 09:03:33 UTC
You are surely right, strlen may not be the correct function to apply. I did not find a helpful comment, what "indexed" actually is, and thought, it is ok, if some maintainer knows better, how to get the length of a display line in bytes and replaces the strlen.

What i want to get here is the length of the lines above the xterm, that are not visible, but part of the wrapped line, whose last parts are visible in line 0 (offset) i.e. the first displayed line and probably more. If you want to see the issue, produce wrapped lines e.g. with ps -ewwf , enable scrolling and enough saveLines. Then scroll, so you see the last parts of a long line on top of the xterm. Double click on some field in the first line. Nothing is selected, because "actual" (may i request to rename this variable to sth. more specific ?) contains the offset of the click position of the really entire wrapped text line and is much higher than the length of make_indexed_text, that returns only the visible part. So "actual" must be reduced by the length of the invisible part of the line, which i want to compute in make_indexed_text and return it in *l_offs .

A similar phenomenon happens in the last line of an xterm, if it contains, say, the first part of a wrapped line and the second line is below the xterm. When you double-click a field in this last line, nothing is selected (but this depends somewhat on how long the real line is). This is, because the while loop does not cover this last line with row index 23, if xterm is 24 lines high. Thus the <= in row <= screen->max_row); . The case, that there is no more line underneath the visible part, is handled by (ld = GET_LINEDATA(screen, row)) != NULL , so no problem here. I took the row increment out of the condition, cause frankly i do not like statements within expressions, cause for me it makes things harder to understand.

The additional offset by one is logical. LastTextCol delivers the last column position in a display line, which is line length minus 1. If you want to see the phenomenon caused by this mistake, produce a long wrapped line. Then on the last line double-click on the leftmost character of a field. You will see, that the field to the left is selected, not the one you clicked on.