Skip to content

Keep the scroll position when a file enters or leaves edit mode - #862

Open
Havunen wants to merge 3 commits into
devfrom
fix/edit-keeps-scroll
Open

Havunen wants to merge 3 commits into
devfrom
fix/edit-keeps-scroll

Conversation

@Havunen

@Havunen Havunen commented Dec 3, 2026

Copy link
Copy Markdown
Member

Clicking Edit on a file scrolled down in the read-only preview, or in its diff, opened the editor at the top. The read-only views and the editor are separate widgets with their own scroll handles, and nothing passed the position between them.

The top visible file line (and how much of it is scrolled away, plus the sideways offset) is now handed to the other view of the same file when the mode flips, in both directions:

  • Preview ↔ editor, including re-entering a file edited before, restored unsaved edits, Save, Save-and-exit and Cancel.
  • Diff rows ↔ editor: full, collapsed and patch rows, inline and split. Rows the file no longer has, and hunk headers, are stepped over to the next line the file has.
  • Caret: a caret that would be out of view after Edit moves onto a visible row, so the first keystroke does not scroll back to it. A caret already in view stays.

The place is a line, not a pixel offset, because the views wrap at different widths and a diff has rows the file does not.

Not changed: Edit from a rendered markdown, SVG or diagram view still opens at the top. For a staged or commit diff the new side is not the working-tree file, so the line carried over is approximate.

Validation

  • cargo fmt --check and cargo clippy --locked -p gitcomet-ui-kit -p gitcomet-ui-gpui --tests -- -D warnings pass on the final commit.
  • cargo test -p gitcomet-ui-kit: 616 passed on the final commit.
  • cargo test -p gitcomet-ui-gpui --lib: 4457 passed on the second commit. Not run on the final commit: the local build of that test binary died with a rustc SIGSEGV 23 times in a row (a machine fault, kernel general-protection faults in libLLVM). CI is the first full run of it.
  • New tests: 25 pane tests in panels/tests/file_edit_scroll.rs and 10 in the text input's tests/scrolling.rs. Each was run with its fix removed and failed, except two that do not isolate their fix (an_editor_that_failed_to_read_hands_the_place_back, a_place_inside_a_wrapped_line_stays_in_that_line).
  • No test covers: the diagram exclusion, the reload offset cleared on repository change, a wide row first seen in the editor, the collapsed diff on the way back, the patch body, and hosted panes with inline views.
  • Run in the app under Xvfb: preview ↔ editor with wrap off and on, and the split full diff of an unstaged file ↔ editor, keep the same top line.

🤖 Generated with Claude Code

Havunen and others added 3 commits December 3, 2026 13:49
…mode

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Edit from the diff of a file (full, collapsed or patch rows, inline or
split) opened the editor at the top. The diff's rows now hand over the
first file line at the top of the list, and take it back on leaving.

Also fixes cases the first hand-over missed: a caret left out of view
when one wrapped line fills the view or the view is panned sideways, a
place inside lines a save adds, Cancel, a failed read, rendered
diagrams, snapped row heights at fractional zoom, a preview shorter than
the buffer, late wrap estimates, and a kept reload offset leaking into
another repository.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A place waiting for a diff or preview that never got its rows could be
taken by the other view of the same file, or fire much later on rows of
another diff. It now goes when its surface leaves the screen or settles
with nothing to show. A hosted view row above a line no longer counts
as pixels into that line, and TextInput has one reveal entry point.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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