Repository navigation
Add Previous/Next change navigation buttons to the Diff View - #6668
Conversation
Add up/down navigation buttons to the single-file Diff View toolbar so
users can jump between change regions (hunks) without scrolling, matching
IntelliJ/Android Studio. The buttons bridge the Monaco diff editor to the
header via an instance-scoped DiffNavigationProvider and call Monaco's
goToDiff('previous'|'next'); they disable when the file has no changes.
Closes #6215
Co-authored-by: Orca <help@stably.ai>
Manual validation evidence (Electron)Validated on the real Orca dev build (this branch's worktree) against a throwaway repo whose
Verdict from the validation pass: LAND. Static checks (typecheck, oxlint, localization catalog) pass; 7 unit/component tests pass. Screenshots demonstrating each state were captured during validation; I can drag them into this thread on request (image upload isn't available from my automation path). |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/editor/diff-navigation-context.test.tsx (1)
24-27: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winCover the stale
onDidUpdateDiffcallback path too.This suite verifies the stale
unregisterDiffEditorguard, but it never proves that an update fromoldEditoris ignored afternewEditortakes over. A regression in the provider's fast-swap update guard would still pass here and could flipchangeCountback to a stale value in the header. Consider makingdisposeclear the stored callback and adding an assertion likeoldEditor.fireUpdate()leavescaptured?.changeCountat4.Suggested test adjustment
function createFakeEditor(initialCount: number): FakeDiffEditor { let count = initialCount let updateCallback: (() => void) | null = null const editor = { getLineChanges: () => (count > 0 ? Array.from({ length: count }, () => ({})) : []), goToDiff: vi.fn(), onDidUpdateDiff: (cb: () => void) => { updateCallback = cb - return { dispose: () => {} } + return { + dispose: () => { + updateCallback = null + } + } }, setLineChanges: (next: number) => { count = next }, fireUpdate: () => updateCallback?.() } as unknown as FakeDiffEditor return editor }it('ignores a stale unregister for an editor that is no longer current (identity guard)', () => { mount() const oldEditor = createFakeEditor(1) const newEditor = createFakeEditor(4) // Fast-swap: new editor registers before the old one's dispose fires. act(() => captured?.registerDiffEditor(oldEditor)) act(() => captured?.registerDiffEditor(newEditor)) expect(captured?.changeCount).toBe(4) + act(() => { + oldEditor.setLineChanges(9) + oldEditor.fireUpdate() + }) + expect(captured?.changeCount).toBe(4) + act(() => captured?.unregisterDiffEditor(oldEditor)) // New editor's count is intact and nav still routes to it. expect(captured?.changeCount).toBe(4)Also applies to: 97-114
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: da87b2de-859c-44c7-ad6f-6ead4b79e5a8
📒 Files selected for processing (10)
src/renderer/src/components/editor/DiffViewer.tsxsrc/renderer/src/components/editor/EditorPanel.tsxsrc/renderer/src/components/editor/EditorPanelHeader.tsxsrc/renderer/src/components/editor/diff-navigation-context.test.tsxsrc/renderer/src/components/editor/diff-navigation-context.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.json
Address CodeRabbit nitpick: prove that an update fired from a replaced editor is ignored after a new editor registers (the subscription is disposed on re-register). The fake editor's dispose now clears its callback, matching real Monaco subscription semantics. Co-authored-by: Orca <help@stably.ai>
|
Addressed the nitpick in 57bc540 — the fake editor's |
# Conflicts: # src/renderer/src/components/editor/EditorPanel.tsx # src/renderer/src/i18n/locales/es.json
|
This really nice to push The main thing I noticed is it's mouse-only. The commenter on #6215 asked for F7/Shift+F7 specifically, which is what VS Code and JetBrains do by default. Your goToDiff wiring made it easy to build on, so I put up a follow-up stacked on this branch (#8240) that adds the keyboard shortcuts through the same provider — plus it translates the Previous/Next change strings (still English in es/ja/ko/zh) and shows the shortcut in the button tooltips. It's based off this branch, so this one needs to land first. Couple of small things, not blockers:
|
|
Thanks—this is a great follow-up. I agree F7/Shift+F7 is the right keyboard behavior, and keeping it rebindable through the existing keybinding system sounds ideal. #6668 is merged now, so I’m reviewing #8240 next and will retarget it to Also noted on the TooltipProvider consolidation and provider scope. I’m moving the TooltipProvider DRY cleanup into a focused follow-up so it doesn’t muddy the keyboard/i18n review. |
Stacks on the Previous/Next change buttons (stablyai#6668) to add keyboard navigation for single-file diffs, matching VS Code / JetBrains diff review. - Register editor.nextChange (F7) / editor.previousChange (Shift+F7) in the keybinding registry (Editors group) so they show in Settings and stay rebindable. - Teach the keybinding normalizer function keys (F1-F24) and make them first-class in the bare-key safety model (safe standalone or with Shift, opt-in per action) - F7 was previously unbindable. - Install a capture-phase listener from DiffNavigationProvider so keyboard and the existing header buttons share one goToDiff path; works on read-only and editable single-file diffs. - Translate the Previous/Next change strings for es/ja/ko/zh. Refs stablyai#6215
* feat(diff): add F7/Shift+F7 keyboard navigation for diff changes Stacks on the Previous/Next change buttons (#6668) to add keyboard navigation for single-file diffs, matching VS Code / JetBrains diff review. - Register editor.nextChange (F7) / editor.previousChange (Shift+F7) in the keybinding registry (Editors group) so they show in Settings and stay rebindable. - Teach the keybinding normalizer function keys (F1-F24) and make them first-class in the bare-key safety model (safe standalone or with Shift, opt-in per action) - F7 was previously unbindable. - Install a capture-phase listener from DiffNavigationProvider so keyboard and the existing header buttons share one goToDiff path; works on read-only and editable single-file diffs. - Translate the Previous/Next change strings for es/ja/ko/zh. Refs #6215 * test(diff): cover change navigation shortcuts * fix(diff): use shortcut chips in navigation tooltips --------- Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
…i#6668) * feat(diff): add Previous/Next change navigation buttons to Diff View Add up/down navigation buttons to the single-file Diff View toolbar so users can jump between change regions (hunks) without scrolling, matching IntelliJ/Android Studio. The buttons bridge the Monaco diff editor to the header via an instance-scoped DiffNavigationProvider and call Monaco's goToDiff('previous'|'next'); they disable when the file has no changes. Closes stablyai#6215 Co-authored-by: Orca <help@stably.ai> * test(diff): cover stale onDidUpdateDiff guard in fast-swap Address CodeRabbit nitpick: prove that an update fired from a replaced editor is ignored after a new editor registers (the subscription is disposed on re-register). The fake editor's dispose now clears its callback, matching real Monaco subscription semantics. Co-authored-by: Orca <help@stably.ai> * fix(diff): isolate navigation registration updates * fix(diff): use arrows for change navigation * fix(editor): tighten header action spacing --------- Co-authored-by: Orca <help@stably.ai> Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
* feat(diff): add F7/Shift+F7 keyboard navigation for diff changes Stacks on the Previous/Next change buttons (stablyai#6668) to add keyboard navigation for single-file diffs, matching VS Code / JetBrains diff review. - Register editor.nextChange (F7) / editor.previousChange (Shift+F7) in the keybinding registry (Editors group) so they show in Settings and stay rebindable. - Teach the keybinding normalizer function keys (F1-F24) and make them first-class in the bare-key safety model (safe standalone or with Shift, opt-in per action) - F7 was previously unbindable. - Install a capture-phase listener from DiffNavigationProvider so keyboard and the existing header buttons share one goToDiff path; works on read-only and editable single-file diffs. - Translate the Previous/Next change strings for es/ja/ko/zh. Refs stablyai#6215 * test(diff): cover change navigation shortcuts * fix(diff): use shortcut chips in navigation tooltips --------- Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
What changes
Adds Previous change (↑) and Next change (↓) buttons to the single-file Diff View toolbar (the editor header, next to the side-by-side toggle). Clicking them jumps the viewport from one change region (hunk) to the next/previous within the file — cyclic at the ends — so you no longer have to scroll to find each change. Inspired by IntelliJ/Android Studio.
What does not change: This is scoped to the single-file diff surface (diff tabs and the per-file "Changes" view). The multi-file/combined diff viewer is intentionally untouched — the buttons do not render there. No keyboard shortcut, setting, or diff-rendering behavior changes. Buttons are disabled when the file has no changes.
Closes #6215
Design approach
The Monaco diff editor instance lives in
DiffViewer, while the toolbar lives in a siblingEditorPanelHeader, three levels up the tree. Rather than prop-drill a ref and a re-render signal through every intermediate (markdown/CSV/image) branch, a small instance-scopedDiffNavigationProvider(one per editor pane, mounted inEditorPanelInner) bridges the two:DiffViewercallsregisterDiffEditor(editor)on mount andunregisterDiffEditor(editor)on dispose / large-diff fallback.changeCountin React state, recomputed fromeditor.getLineChanges()on register and on Monaco'sonDidUpdateDiff.goToDiff('previous'|'next')and aredisabledwhenchangeCount === 0.An identity guard on register/unregister (and the update callback) handles the fast tab-swap race so a stale dispose can't wipe a freshly-registered editor. Buttons reuse the existing header
<button>+Tooltippattern andlucide-reactChevronUp/ChevronDown; strings go through the i18n catalog witharia-labels on the icon-only buttons.Design review
Ran the design doc through an automated design-review loop (Claude + Codex reviewers, 2 rounds) until clean (READY). Findings folded in: identity-carrying
unregistercontract (the original bare-nullsignature made the fast-swap guard unimplementable), explicit "changeCount must be state, not a ref" reasoning, single-subscription ownership, and a corrected precedent reference (tab-group/tab-drag-context.tsx). Scope stayed on the single-file surface throughout.Implementation & deviations
Files: new
diff-navigation-context.tsx(+ test), and edits toDiffViewer.tsx,EditorPanel.tsx,EditorPanelHeader.tsx, plus i18n catalog entries in all five locales. No deviations from the reviewed design.Completeness verification
A read-only verification pass checked the implementation against every requirement and edge case in the design doc: COMPLETE, no omissions. (Non-English locales carry the English fallback string — the expected output of the catalog sync; real translation is a downstream step.)
Headline behavior status
Implemented — and confirmed running in the real app (not fixture-only). The buttons call
goToDiffon the live Monaco editor registered fromDiffViewer's production mount path;changeCountfromgetLineChanges()drives the enabled state.Perf audit
Touched hot paths: the new provider,
EditorPanel's wrap, andDiffViewer's register/unregister. Audit result: clean, no fixes needed. Key point —changeCountflips do not re-render Monaco/EditorContent: thechildrenelement reference is preserved across the provider's own re-render, so only the two context consumers (header + DiffViewer wrapper) re-render, and only on infrequent diff-recompute events (not per keystroke/scroll). TheonDidUpdateDiffsubscription is bounded to one per provider and disposed on unregister/re-register/unmount; no editor retention or leak. Type-only Monaco import, so no startup cost. Coverage is via the deterministic unit test below rather than a benchmark.Code review
Ran an iterative review loop, then re-ran two independent reviewers in parallel focused on (1) lifecycle/disposal/provider-scoping and (2) button render/gating/i18n/accessibility. Both returned no CONFIRMED bugs. They verified: per-pane provider isolation (no cross-split bleed), the fast-swap identity guard holds, single bounded subscription with full disposal, correct i18n hash keys with matching tooltip + aria-label, correct combined-diff exclusion (double-gated), and correct icon→direction wiring. The one PLAUSIBLE-but-unreachable note (Monaco
goToDiffon a disposed editor) is guarded because every count-clearing path disables the buttons first.Manual validation (brennan-test-changes)
Validated on the real Electron surface (verdict: LAND). Tested on a throwaway repo with a 3-hunk file:
Screenshots showing the buttons in the header, the disabled state, and their absence on the combined viewer are attached in a follow-up comment.
Static checks & tests
typecheck:web(tsgo): cleanoxlinton touched files / editor dir: cleanverify:localization-catalog: clean (both new keys present, parity across es/ja/ko/zh)diff-navigation-context.test.tsx(3 cases: nav routing +goToDiff; 0→NonDidUpdateDiffre-render proving count is state; stale-unregister identity-guard no-op) plus existingChangesModeView/EditorContenttests: 7 passingCross-platform / SSH
Renderer-only UI on the already-mounted Monaco diff editor — no IPC, no filesystem, no platform branches, no keyboard shortcut. Works identically for local and SSH-backed worktrees. Icons from the existing
lucide-reactdependency.Assumptions / remaining risk
onDidUpdateDifflistener coexists withDiffViewer's pre-existing auto-scroll listener; both are low-frequency, left separate for clean ownership.Made with Orca 🐋