Bug 448765

Summary: With a dynamic word wrap and a line long enough to overflow the view, view doesn't scroll when needed
Product: [Applications] kate Reporter: Oded Arbel <oded>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: Git   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: screencast showing the problems

Description Oded Arbel 2022-01-19 11:54:16 UTC
SUMMARY
If a line is so long that with "dynamic word wrap" it fills the window, if the cursor needs to move to a point on the same line that it outside the current view window, the view doesn't scroll and the text cursor goes out of the view and is no longer visible.

I can reproduce this with using the END key or with the find in file function, but not with the HOME key...

STEPS TO REPRODUCE
1. Open kate and make the window relatively small.
2. Enable "dynamic word wrap"
3. Open a file with at least one line that is long enough to fill the entire window and overflow it by a bit.
4. Move the text cursor to the beginning of the long line.
5. Press END once, the cursor will move to the end of the current display line (on the right side of the window at the same height as the beginning of the line, but not at the "end of line" character).
6. Press END again.

OBSERVED RESULT
The text cursor disappears from the view, the view is otherwise unchanged.

EXPECTED RESULT
The view should scroll so that the real end of the line of text (the location of the "end of line" character) should move into view and text cursor positioned at the real end of the line.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
KDE Plasma Version: 5.24.80
KDE Frameworks Version: 5.91.0
Qt Version: 5.15.3

ADDITIONAL INFORMATION
Interestingly enough, the behavior of viewing the end of the line and pressing HOME twice is fine - the cursor is moved to the real beginning of the text line and the view is scrolled upwards as expected.

The same behavior can be seen with the "Find in file" functionality: press CTRL+F and enter text that can only be found towards the end of the line in the part that isn't visible in the view.

The cursor will disappear and no match will be shown in the view. When manually scrolling, the found matches can be seen highlighted with the text cursor at the end of the first match. Even if the first few characters typed in the search box can be found at the beginning of the line, the view will not automatically scroll when these first matches are eliminated from the search due to more text being typed, though the view *will* automatically scroll when pressing F3.
Comment 1 Oded Arbel 2022-01-19 12:01:42 UTC
Created attachment 145642 [details]
screencast showing the problems

The attachment shows the behavior with a Java classpath line - very long text with no white space. I first demonstrate the issue with "find in file" and then the HOME and END behaviors.

Note that during the search, first the first match is found relatively close to the top, then - as more text is typed - the first match is moved to the bottom of the view, but low enough that the "scroll before hitting the bottom" behavior of kate is triggered (which, BTW, is a feature I love so much💕), then more text is typed and the first match is found out of the screen and the view does not scroll, as per the bug report.
Comment 2 Bug Janitor Service 2025-02-16 07:49:39 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/786
Comment 3 gwdx 2025-02-16 19:24:41 UTC
Git commit 6a18c1818eec5514bff95e93f97b4baf27f9c091 by Wendi Gan.
Committed on 16/02/2025 at 07:27.
Pushed by cullmann into branch 'master'.

Fix scrolling to search results in wrapped long lines

When dynamic word wrap is enabled, if the search result is located in a very long line and part of the line is currently displayed but the search result is further down, the search result cannot be navigated to after searching.

This commit modifies the return value of KateLayoutCache::displayViewLine to ensure that KateViewInternal::makeVisible can correctly scroll to search results in long lines.

M  +3    -1    src/render/katelayoutcache.cpp

https://invent.kde.org/frameworks/ktexteditor/-/commit/6a18c1818eec5514bff95e93f97b4baf27f9c091