Skip to content

global hunk navigation - #59

Merged
umputun merged 8 commits into
umputun:masterfrom
korjavin:global-hunk-navigation
Apr 8, 2026
Merged

umputun merged 8 commits into
umputun:masterfrom
korjavin:global-hunk-navigation

Conversation

@korjavin

@korjavin korjavin commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Forward cross-jump: Pressing ] at the last hunk of a file automatically crosses the boundary into the next file and lands your cursor on its first hunk.
  • Backward cross-jump: Pressing [ 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

korjavin and others added 6 commits April 7, 2026 20:59
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]>
@korjavin
korjavin requested a review from umputun as a code owner April 7, 2026 17:48
@korjavin

korjavin commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 fileTree helpers (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.

Comment thread app/ui/model.go
Comment on lines 795 to +799
m.positionOnAnnotation(a)
return m, blameCmd
}

// handle pending hunk jump after cross-file hunk navigation

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

the implementation is solid, tests are good, and the pendingHunkJump pattern is consistent with pendingAnnotJump. couple things before merge:

  1. 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

  2. unrelated refactoring - openAnnotList() extraction in annotlist.go and helpActive() helper in model.go are not part of the feature. openAnnotList is called only once, and helpActive just wraps an inline boolean. pls revert these and keep the PR focused on hunk navigation

  3. minor edge case - when pendingHunkJump lands on a file with zero hunks (all context lines), diffCursor stays at -1 (forward) or len(m.diffLines) (backward). unlikely in practice but a one-line fallback to skipInitialDividers() would fix it

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

all 3 items addressed, lint clean, tests pass. lgtm, thx

@umputun
umputun merged commit 26a3730 into umputun:master Apr 8, 2026
sanchesfree pushed a commit to sanchesfree/revdiff that referenced this pull request Apr 8, 2026
* 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]>
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.

3 participants