Skip to content

Fix selection extending issues#637

Open
liweitianux wants to merge 4 commits intolxqt:masterfrom
liweitianux:fix-selection-extending
Open

Fix selection extending issues#637
liweitianux wants to merge 4 commits intolxqt:masterfrom
liweitianux:fix-selection-extending

Conversation

@liweitianux
Copy link
Copy Markdown

This PR fixes the selection extending that would go beyond the visible screen, for both word mode and line mode.

In addition, this fixes a related scrolling issue with Shift+click range selection: when the start anchor is scrolled off the visible screen, the Shift+click selected region becomes wrong, with the row number of the start anchor being changed to make it appear in the visible screen.

For debug builds, the function will fail when called with out of display
coordinates, allowing to spot addressing errors. For regular builds,
it will limit coordinates to valid area without triggering errors.

Obtained-from: Konsole
Commit: KDE/konsole@674de97
When a "word" (e.g., a path) wraps across the line and has a part
scrolled off the visible screen, a double click previously could only
select the visible part.  This patch fixes the problem.

Obtain-from: Konsole
Commits:
- KDE/konsole@914067d
- KDE/konsole@4e09f08
- KDE/konsole@6d9d49a
When extendSelection() is called to extend a region, the "start" anchor
may be scrolled off the visible screen.  In that case, findWordStart()
and findWordEnd() would cause out-of-bound access in loc(), which would
either hit Q_ASSERT() to crash the program or clamp the (x,y) into the
visible screen.

Konsole "fixed" this issue by ensuring the point given to findWordStart()
and findWordEnd() in the visible screen [1].  However, that would break
the Shift+click range selection function.  The correct fix is to
correctly handle the initial out-of-screen pointer in findWordStart()
and findWordEnd(), as we did here.

[1] KDE/konsole@f7d54a6

Assisted-by: Claude Sonnet 4.5
The line selection mode (e.g., triple click) previously could only
select the visible part of a line.  Similar to findWordStart() and
findWordEnd(), add findLineStart() and findLineEnd() to determine the
line start and end, correctly handling the off-screen part of a line.

Obtained-from: Konsole
Commits:
- KDE/konsole@6df0b5b
- KDE/konsole@da08042
- KDE/konsole@4284d99
@tsujan
Copy link
Copy Markdown
Member

tsujan commented Apr 23, 2026

Many thanks!

A preliminary test showed me that it didn't work as expected (alongside #636) when the start of shift+selection was below its end but outside the visible part of the text: the selection was done only in the visible part in this case.

@tsujan
Copy link
Copy Markdown
Member

tsujan commented Apr 23, 2026

Oh, my bad! I'd applied the patch incorrectly. It seems to work. Very sorry for my previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants