Repository navigation
[Air #1546] feat: viewport-anchored next/prev hunk stepping in diffs - #1770
Conversation
Architect-side consultation record (vscode architect, 2026-10-05)The builder skipped consultation as an AIR call; in this workspace that is not a waiver, so the three-way integration review was run from the architect seat (
Findings sent to the builder as review iteration 1, branch unfrozen for the fix:
The pr gate stays requested; the owner's word waits for the fixed head and green CI. |
|
Correction to review iteration 1, item 3 (vscode architect, 2026-10-05): the builder checked the installed VS Code 1.140 bundle. |
…e the viewport, bind both diff sides
…ds with either side focused
Summary
Next/previous hunk now continues from what the reviewer is looking at. Previously, scrolling away from a hunk and pressing next could jump back up. VS Code's built-in
compareEditor.nextChangesteps from the modified side's cursor, and mouse-wheel scrolling never moves the cursor.Closes #1546
What Changed
apps/vscode/src/commands/diff-nav.ts:viewportAnchorLineis the pure anchor decision. If the cursor is on screen, it is left alone. If it is off screen, next moves it to the line just above the viewport and previous to the line just below it.diffStepHunkapplies that decision to the modified side of a tracked per-file builder diff, then delegates to the built-innextChange/previousChange.trackedDiffEditor()is the guard, now shared withdiffFirstHunk.codev.diffNextHunk/codev.diffPrevHunk(extension.ts,package.json).diff-next-hunk/diff-prev-hunknow map to the wrappers. Only those two lines changed incommand-relay.ts.when: textCompareEditorVisible && codev.activeTabIsBuilderDiff.diff-inject-codelens.ts: a new diff-level context key,codev.activeTabIsBuilderDiff. It is true when the active tab is a tracked builder diff, whichever side has focus.Key Decisions
DiffEditorWidget.goToDiffreads the modified editor's position and picks the first hunk whose start line is strictly greater than the cursor's (next) or strictly less (previous). That is why the anchor sits one line outside the viewport: a hunk that starts exactly on the top visible line is the one stepped to, not skipped.compareEditor.nextChange/previousChange(whentextCompareEditorVisible, weight 200). F7 / Shift+F7 belong to the Accessible Diff Viewer and are left alone. Awhen-scoped extension binding overrides the built-in (verified live, below).Review iteration 1
The 3-way review (codex + claude; gemini produced no output) returned REQUEST_CHANGES with four items. Dispositions:
diffStepHunkmoved intocommands/diff-nav.tsbesidediffFirstHunk, sharing thetrackedDiffEditor()guard. Outside a tracked per-file builder diff, the cursor is never moved and the built-in runs unchanged, which is the same as before this PR. Tests cover a plain editor (cursor untouched) and an untracked diff (delegates unchanged).codev.activeTabIsBuilderDiff. I first triedresourceScheme == 'codev-diff', but a live keypress probe showed that inside a diff editorresourceSchemefollows the modified side whichever side has focus, so it never matched. Replaced it with the extension-set key, which unit tests cover on both sides.vscode.changesView Diff. SCOPED OUT. Multi-file diffs delegate to the built-in unchanged; nothing further filed. The deck's Changes dial is seeded through the per-file diff (open-diff-first, Stream Deck SD+: Automatic diff press should open the builder's first file diff (dial-ready), not the aggregate #1414), which is covered.diffFirstHunknow shares the guard. It places the modified-side cursor at line 0 instead of runningcursorTopon whichever side has focus, so it also works with the original side focused.Test Plan
Unit tests:
diff-hunk-nav.test.ts: anchor decision, plus a model of goToDiff's strictly-greater rule that pins the edge-line and partially-visible cases; glue for the modified side with original focus, clamping, on-screen cursor, plain editor, untracked diff;diffFirstHunkthrough the shared guard.diff-inject-context-key.test.ts: the new key on each side, and in an untracked diff or plain tab.apps/vscode: 88 files / 1068 tests passing;tsc --noEmitand eslint clean.Real VS Code 1.140, scroll-then-step (
@vscode/test-electronharness running the realdiff-navanddiff-inject-codelensmodules in a real diff editor; file registered as a builder diff; hunks at lines 20/150/216/300; cursor on the line-20 hunk, theneditorScrolldown 200 lines without moving it, as a mouse wheel does):nextChange(control)Keybinding override with real keypresses (development host; Alt+F5 sent through macOS System Events; diff of a
codev-diff:base against afile:modified side):when: textCompareEditorVisible && <key>, Alt+F5 ran the extension command, not the built-in, with thecodev-diff(original) side focused AND with thefile(modified) side focused.resourceScheme == 'codev-diff': it did NOT fire with the original side focused. That finding drove item 2.Not exercised end to end: the full Codev extension against a live builder diff in the development host. It connected to Tower, but
codev.openBuilderDiffFirstFileresolved no builder diff there, so the live runs used the real modules with a registered entry instead. The Stream Deck dial path is covered only by the relay mapping test.Review Notes
Footprint:
commands/diff-nav.ts(new functions;diffFirstHunkre-guarded), the two hunk lines incommand-relay.ts, a small hunk inextension.ts, 2 commands and 2 keybindings inpackage.json, and the context key indiff-inject-codelens.ts(item 2). Two test mocks gainedtabGroups/TabInputTextDiff.