Repository navigation
feat: preserve cursor position across compact diff toggle - #274
Merged
Merged
Conversation
toggling compact mode (C) re-fetches the current file and used to reset the cursor to the first hunk via the shared handleFileLoaded path. now the cursor position is captured as a semantic anchor (source line plus change type, with a nearest-hunk fallback) before the toggle and restored after the re-fetch, so the reviewer stays on the same hunk instead of jumping to the top. the anchor is seq-tagged to the exact reload so an intervening file switch or R reload discards it. Related to #271
- [major] [app/ui/loaders.go] applyCompactAnchor could land the cursor on a collapsed-hidden line (removed-line anchor or a modify hunk's removed start after expandedHunks is cleared); call adjustCursorIfHidden in both direct-set branches so the restored cursor stays visible in collapsed mode. doc note in CLAUDE.md + godoc updated. - [test-gap] [app/ui/loaders_test.go] add stale-anchor seq-drop test - [test-gap] [app/ui/loaders_test.go] make the divider-anchor subtest discriminate hunk-fallback from skipInitialDividers - [test-gap] [app/ui/loaders_test.go] exercise applyCompactAnchor with a removed-line anchor - [test-gap] [app/ui/loaders_test.go] cover collapsed+compact keeps the restored cursor visible - [test-gap] [app/ui/handlers_test.go] add compact->full C-key integration test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
preserves the diff cursor position across the compact toggle (
C) instead of resetting to the first hunk.what changed:
toggleCompactModecaptures a semantic anchor (source line + change type, with a nearest-hunk fallback) before the re-fetch and restores it inhandleFileLoadedviaapplyCompactAnchor. The anchor is seq-tagged to the exact reload, so an intervening file switch orRreload drops a stale anchor. Compact→full always resolves the exact line (full is a superset); full→compact falls back to the nearest hunk when a context line is dropped. In collapsed modeadjustCursorIfHiddenkeeps the restored cursor off a hidden removed line.scope: this keeps the cursor on the same line and centers the view on it, not the exact scroll offset. The compact and full views show different content, so an identical on-screen position often can't exist (e.g. 20 rows down in full but only 5 rows above the hunk in compact), and top/bottom hunks clamp to the edge. So it's "same hunk visible, cursor on the right line" rather than pixel-exact scroll restoration.
Related to #271.