Skip to content

Keep the caret when the open file is reloaded - #162

Open
chessing234 wants to merge 6 commits into
omacom:masterfrom
chessing234:reload-keeps-caret
Open

chessing234 wants to merge 6 commits into
omacom:masterfrom
chessing234:reload-keeps-caret

Conversation

@chessing234

Copy link
Copy Markdown

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. namesARelativeFileByItsFullPath fails on this Mac because /var is /private/var; that comparison is unchanged here.

Made with Cursor

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.
@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P2 Reload loses the reading position ▶

Summary

Reloading a file now restores the caret and scroll position, while fresh opens still start at the top.

  • Reloading a file keeps the writer's place in the text.

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

Comment thread src/Main.qml
Comment on lines +335 to +337
if (keepView) {
editorFlick.scrollTo(editorFlick.clampContentY(scroll));
editorFlick.ensureCursorVisible();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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

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.

1 participant