Repository navigation
global hunk navigation - #59
Conversation
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ed positioning Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add handleHunkNav method to diffview.go that moves to next/prev hunk regardless of which pane has focus. When at the last hunk of a file, automatically navigates to the next file and lands on its first hunk (and vice versa for backward navigation). Hunk nav keys are moved to the global key switch so they work from the tree pane too. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Extracted openAnnotList helper and helpActive predicate to reduce handleKey cyclomatic complexity from 22 to 20, satisfying gocyclo lint. All tests pass, lint clean. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
@copilot |
There was a problem hiding this comment.
Pull request overview
Adds global [ / ] hunk navigation so users can traverse hunks across multiple files without manually switching files, while keeping single-file mode behavior unchanged.
Changes:
- Implement global hunk navigation that crosses to adjacent files at hunk boundaries in multi-file mode.
- Add
fileTreehelpers (hasNextFile/hasPrevFile) plus model state (pendingHunkJump) and extensive unit tests. - Update user-facing docs (README + site docs) and add a completed implementation plan doc.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
app/ui/diffview.go |
Adds handleHunkNav to jump hunks and cross-file at boundaries. |
app/ui/model.go |
Adds pendingHunkJump, wires hunk nav into global key handling, and applies pending jump on file load. |
app/ui/filetree.go |
Adds non-wrapping hasNextFile / hasPrevFile helpers for boundary detection. |
app/ui/annotate.go |
Clears pendingHunkJump when deleting annotations triggers potential file reload. |
app/ui/annotlist.go |
Refactors annotation list opening into openAnnotList(). |
app/ui/model_test.go |
Adds unit tests for pending hunk jump behavior and cross-file hunk navigation scenarios. |
app/ui/filetree_test.go |
Adds tests for hasNextFile / hasPrevFile. |
README.md |
Documents cross-file hunk navigation behavior in multi-file mode. |
site/docs.html |
Updates keyboard shortcuts documentation for [ / ]. |
docs/plans/completed/2026-04-07-global-hunk-navigation.md |
Records the completed implementation plan and testing checklist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| m.positionOnAnnotation(a) | ||
| return m, blameCmd | ||
| } | ||
|
|
||
| // handle pending hunk jump after cross-file hunk navigation |
There was a problem hiding this comment.
If both pendingAnnotJump and pendingHunkJump are set (e.g., user triggers cross-file hunk nav, then quickly jumps via annotation list before the file load completes), the pending annotation jump branch returns without clearing pendingHunkJump. This can leave a stale pendingHunkJump that will unexpectedly affect the next file load. Clear pendingHunkJump when handling a pendingAnnotJump (and consider adding a regression test covering this interleaving).
umputun
left a comment
There was a problem hiding this comment.
the implementation is solid, tests are good, and the pendingHunkJump pattern is consistent with pendingAnnotJump. couple things before merge:
-
cross-file should be opt-in - changing the default behavior of
[/]can surprise existing users who are used to them stopping at file boundaries. pls add a flag, smth like--cross-file-hunks(default false), with INI config support. when off,[/]stay within the current file as before -
unrelated refactoring -
openAnnotList()extraction inannotlist.goandhelpActive()helper inmodel.goare not part of the feature.openAnnotListis called only once, andhelpActivejust wraps an inline boolean. pls revert these and keep the PR focused on hunk navigation -
minor edge case - when
pendingHunkJumplands on a file with zero hunks (all context lines),diffCursorstays at-1(forward) orlen(m.diffLines)(backward). unlikely in practice but a one-line fallback toskipInitialDividers()would fix it
umputun
left a comment
There was a problem hiding this comment.
all 3 items addressed, lint clean, tests pass. lgtm, thx
* add plan: global-hunk-navigation * feat: add hasNextFile/hasPrevFile helpers to fileTree Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * feat: add pendingHunkJump field for cross-file hunk navigation deferred positioning Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * feat: implement global hunk navigation with cross-file jump Add handleHunkNav method to diffview.go that moves to next/prev hunk regardless of which pane has focus. When at the last hunk of a file, automatically navigates to the next file and lands on its first hunk (and vice versa for backward navigation). Hunk nav keys are moved to the global key switch so they work from the tree pane too. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * feat: verify acceptance criteria and fix handleKey cyclomatic complexity Extracted openAnnotList helper and helpActive predicate to reduce handleKey cyclomatic complexity from 22 to 20, satisfying gocyclo lint. All tests pass, lint clean. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * feat: update docs for cross-file hunk navigation and complete plan Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Reviews findings * Fix lint failures --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Summary
This PR enhances the
[and](previous/next hunk) shortcuts to support seamless global navigation across multiple files in a diff.Idea: Global Navigation & Cross-File Jump
Previously, navigating changes using
[and]was strictly confined to the currently active file. If you reached the last hunk of a file, you were required to manually select the next file from the file tree.With this update, hunk navigation becomes globally aware:
]at the last hunk of a file automatically crosses the boundary into the next file and lands your cursor on its first hunk.[at the first hunk of a file elegantly jumps back to the previous file, landing on its last hunk.This creates an uninterrupted, fluid experience, allowing you to comfortably review an entire multi-file diff end-to-end using just two keys. Single-file mode remains completely unaffected and will continue to confine navigation to the current file.
Proudly done with ralphex