Repository navigation
fix(ui): preserve unreviewed tree scroll - #259
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the sidepane file tree behavior when using the unreviewed-only filter by keeping the viewport stable as files are marked reviewed and by preserving scroll position across file-list reloads, eliminating disruptive scroll jumps (Issue #258).
Changes:
- Preserve the file tree viewport offset when the unreviewed-only list is rebuilt so the next selected file stays on the same visible row after marking reviewed.
- Preserve unreviewed-tree scroll offset across reloads, while resetting it when the unreviewed filtered tree becomes empty.
- Add unit tests covering row-preserving advance, empty-state offset reset, and reload scroll-offset preservation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/ui/sidepane/filetree.go | Preserves offset during unreviewed-filter rebuilds and avoids unnecessary viewport resets so EnsureVisible scrolls only when needed. |
| app/ui/sidepane/filetree_test.go | Adds tests for row-stable selection advance and for resetting offset when the unreviewed filtered tree becomes empty. |
| app/ui/loaders_test.go | Adds a model-level test ensuring reloads preserve the unreviewed scroll offset for a stable viewport. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
umputun
left a comment
There was a problem hiding this comment.
core fix is right and does what #258 asked. Verified the reload test fails without it (offset clamps to 2 instead of 4), and build/test/lint/race are all green locally. Two viewport nits, one of them a small regression this PR adds.
F toggle scrolls the ./ header off-screen (should fix before merge). selectAfterRebuild (app/ui/sidepane/filetree.go:445) no longer resets offset in its no-anchor fallback, and ToggleUnreviewedFilter reaches that fallback with both args empty. So toggling F while the tree is scrolled down leaves offset clamped to the first file's index (1) instead of 0, and the leading ./ directory header gets scrolled off the top. It's the milder version of the same jump #258 was about. The mark-reviewed and reload paths return early via SelectByPath, so resetting in the fallback doesn't touch the fix:
if preferred != "" && ft.SelectByPath(preferred) {
return
}
ft.offset = 0 // no anchor survived, reset viewport to top
for i, e := range ft.entries {
if !e.isDir {
ft.cursor = i
return
}
}worth a small test for the toggle-from-scrolled case, none of the new ones exercise it.
offset is preserved by index, not visible row (optional). on a reload that changes the unreviewed set above the current viewport, the selected file's row drifts by the number of rows added or removed above it, since offset is kept by absolute index rather than by visible row (cursor - offset). It's rare, it's outside the mark-reviewed case (#258 is exact there), and it's still better than the old full reset, so fine to defer. If you want it airtight later: capture visibleRow = cursor - offset before Rebuild in handleFilesLoaded, then set offset = clamp(newCursor - visibleRow) once the selection is restored.
|
Addressed both viewport points. The resulting behavior is:
Manually smoke-tested both entering |
umputun
left a comment
There was a problem hiding this comment.
both viewport points from last round are handled and the fix itself is correct. Build/test/lint/race are green, and the visible-row anchoring (offset = max(cursor - visibleRow, 0)) is the exact inverse of the capture, so the row survives index shifts. One thing still open.
the ./-header regression fix has no test. The reset is in place: selectAfterRebuild zeroes offset on the non-empty no-anchor fallback at app/ui/sidepane/filetree.go:459. But nothing reaches that path from a scrolled state. TestFileTree_EnableUnreviewedFilterPreservesVisibleSelection keeps the selected file unreviewed, so toggling F takes the anchored branch at line 452, not 459. TestFileTree_UnreviewedFilterEmptyStateResetsOffset hits the separate len(entries)==0 early return at 447. So deleting line 459 leaves the whole suite green, and EnsureVisible won't cover for it: after the reset the cursor sits on the first file at index 1, below the ./ header at index 0, so a stale offset still scrolls the header off. This is the toggle-from-scrolled case I flagged last round. Add a filetree_test.go case that reaches 459 from offset > 0 (e.g. select a reviewed file, then ToggleUnreviewedFilter with entries remaining) and asserts offset == 0 and the first entry visible.
optional, take or leave:
selectAfterRebuildrepeatsft.offset = max(ft.cursor-visibleRow, 0)verbatim in thepreviousandpreferredbranches (452, 456). Oneif a || b { ... }covers both.visibleRow := ft.cursor - ft.offsetis re-derived at three call sites (Rebuild,ToggleUnreviewedFilter,RefreshUnreviewedFilter). A smallft.visibleRow()method would name the concept and stop it drifting.- when
ft.unreviewed,Rebuildanchors against the full unfiltered list even thoughRefreshUnreviewedFilterrebuilds the filtered view right after. It's load-bearing only because it carries thecursor - offsetdelta forward, and nothing says so. A one-line comment there would keep a futureRebuildcleanup from silently dropping scroll preservation.
Closes #258.