Skip to content

feat: add {N}G shortcut to jump to source line in diff view#193

Merged
martintrojer merged 1 commit intoagavra:mainfrom
martintrojer:gotoline
Mar 5, 2026
Merged

feat: add {N}G shortcut to jump to source line in diff view#193
martintrojer merged 1 commit intoagavra:mainfrom
martintrojer:gotoline

Conversation

@martintrojer
Copy link
Copy Markdown
Collaborator

  • Add vim-style {N}G command to jump to a source code line number in the current file's diff. The target is the new-side line number shown in the gutter (i.e. the actual source line), not the display row in the TUI.
  • Since diffs only show changed hunks, the requested line may not be present. When no exact match exists, the cursor jumps to the nearest visible diff line and a status bar message explains the approximation. If the file has no diff lines at all, a warning is shown.
  • Digits accumulate in Normal mode and are displayed in the status bar (NORMAL 42) for visual feedback. Pressing G consumes the count; any other key discards it. Plain G without a count still goes to the last file, preserving existing behavior.

Test plan

  • cargo test — all 237 tests pass (17 new)
  • Open a diff, press 4 2 G — cursor jumps to source line 42 (or nearest) in current file
  • Press G without digits — still goes to last file
  • Press digits then a non-G key (e.g. j) — digits are discarded, key handled normally
  • Status bar shows accumulated digits as they're typed
  • Press ? — help popup shows the new {N}G entry

Add vim-style {count}G command that jumps to source code line N
(the new-side line number shown in the gutter) within the current
file. This targets the original source line number, not the display
row in the TUI. Because diffs only show changed hunks, the
requested line may not be visible; when no exact match exists the
cursor jumps to the nearest diff line and a status message explains
the approximation. If the current file has no diff lines at all, a
warning is shown instead.

Digits accumulate in Normal mode and are shown in the status bar
for visual feedback. Pressing G consumes the count and jumps;
any other key discards it. Plain G (no count) still goes to the
last file, preserving existing behavior.
Copy link
Copy Markdown
Owner

@agavra agavra left a comment

Choose a reason for hiding this comment

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

Great feature @martintrojer! Thanks. Feel free to hit the merge button yourself now that you've got write access 😉

@martintrojer martintrojer merged commit 3ccf3d2 into agavra:main Mar 5, 2026
4 checks passed
@martintrojer
Copy link
Copy Markdown
Collaborator Author

@agavra Thanks! Wanted you to have a look before merging! 😉

@martintrojer martintrojer deleted the gotoline branch March 5, 2026 13:52
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.

2 participants