Repository navigation
Keep the caret when the open file is reloaded - #162
chessing234 wants to merge 6 commits into
Conversation
A reload has to know where the writer was. The caret was already reported; the scroll was not, so it could not be put back.
Opening a file and reloading it shared one signal, so the window could not tell them apart. The caret and scroll recorded before the load travel with the signal.
Setting the caret to 0 is a no-op when it is already there, so a selection anchored at the start survived the open and covered the new text.
Starting every open at the top also ran for a reload, so an external change jumped the writer to the first line. A shorter file clamps the caret to the new end instead of leaving it past the text.
The open path has to drop a selection whose caret is already at 0, and a reload has to keep a caret in the middle when the file grows and clamp it when the file shrinks.
A second onContentYChanged is a QML error, so the window would not load. The existing handler clears the link hover; it now records the scroll there too.
[Medium impact] The change affects how the editor places the view when files are opened or reloaded. The PR appears safe to merge, with a non-blocking reading-position issue worth fixing. Findings
SummaryReloading a file now restores the caret and scroll position, while fresh opens still start at the top.
One non-blocking issue remains: reloading can still lose the reading position when the user has scrolled away from the caret. Reviews (1) · Last reviewed commit: "Report the scroll from the handler conte..." · Reviewed by Greptile |
| if (keepView) { | ||
| editorFlick.scrollTo(editorFlick.clampContentY(scroll)); | ||
| editorFlick.ensureCursorVisible(); |
There was a problem hiding this comment.
Reload loses the reading position. When the user scrolls away from the caret, reloading restores the saved scroll and then immediately calls
ensureCursorVisible(). That moves the page back to the caret, even when the file only gained text at the end. Preserve the saved scroll without forcing an off-screen caret into view. Update the test to compare the restored contentY with the saved value; checking only > 0 misses this jump.
Knowledge Base Used: Writing editor interactions
Opening a file still starts at the top, which is what landed in cb9b39c. Reloading that same file went through the same path, so an external change jumped the caret to the first line.
A reload now puts the caret and scroll back, clamped when the file got shorter. A selection that already starts at position 0 is cleared on a fresh open, because writing the caret back to 0 does not drop it.
QT_QPA_PLATFORM=offscreen ./build/omawrite_tests— 126 passed.namesARelativeFileByItsFullPathfails on this Mac because/varis/private/var; that comparison is unchanged here.Made with Cursor