Description
When using j/k keyboard navigation to move between changes in the diff viewer, pressing the spacebar resets the navigation state back to the first change. The expected behavior is that spacebar should scroll the page (standard browser behavior) without affecting the j/k navigation position.
Steps to Reproduce
- Open a PR with multiple changes
- Set view mode to: inline view, full file mode, hidden comments
- Use 'j' key to navigate to the 2nd or 3rd change
- Press spacebar
- Observe: navigation state resets to first change (bug)
- Expected: page should scroll down, j/k position should remain unchanged
Expected Behavior
Pressing spacebar should:
- Scroll the page down by approximately one viewport height (standard browser behavior)
- Preserve the current j/k navigation index so that subsequent j/k presses continue from the same position
Actual Behavior
Pressing spacebar:
- Resets the
currentHunkIndex state to -1 or 0, causing navigation to jump back to the first change
- Next use of 'j' key navigates from the first change instead of continuing from the previous position
Root Cause Analysis
The diff-keymap.ts extension defines key bindings for j, k, PageUp, PageDown, Home, and End keys, but does not define a key binding for spacebar. The spacebar may be triggering a default CodeMirror behavior or being handled elsewhere, which could be resetting the diffNavigationState.currentHunkIndex via state mutations or StateEffect.
Affected file: src/features/diff/components/codemirror/extensions/diff-keymap.ts
The diffNavigationState StateField manages currentHunkIndex for navigation:
- Lines 40-55: State definition
- Lines 85-102: 'j' key binding (increments
currentHunkIndex)
- Lines 104-121: 'k' key binding (decrements
currentHunkIndex)
- Lines 123-170: Page scroll and navigation key bindings
Missing: Spacebar key binding that allows default scroll behavior without affecting state
Additional Context
- This happens with the setup: inline view, full file mode, hidden comments
- The issue specifically occurs when spacebar is pressed after j/k navigation
- The spacebar should behave as default browser scroll behavior (or fall through to CodeMirror's default)
- The j/k navigation index should be preserved when spacebar is pressed
Test Scenario
A reproducible test case would:
- Create a diff with 5+ changes
- Navigate to change 3 using 'j' key twice
- Press spacebar
- Verify that
currentHunkIndex remains at 2 (third change, 0-indexed)
- Press 'j' again and verify it navigates to change 4 (not back to change 2)
Description
When using j/k keyboard navigation to move between changes in the diff viewer, pressing the spacebar resets the navigation state back to the first change. The expected behavior is that spacebar should scroll the page (standard browser behavior) without affecting the j/k navigation position.
Steps to Reproduce
Expected Behavior
Pressing spacebar should:
Actual Behavior
Pressing spacebar:
currentHunkIndexstate to -1 or 0, causing navigation to jump back to the first changeRoot Cause Analysis
The
diff-keymap.tsextension defines key bindings for j, k, PageUp, PageDown, Home, and End keys, but does not define a key binding for spacebar. The spacebar may be triggering a default CodeMirror behavior or being handled elsewhere, which could be resetting thediffNavigationState.currentHunkIndexvia state mutations or StateEffect.Affected file:
src/features/diff/components/codemirror/extensions/diff-keymap.tsThe
diffNavigationStateStateField managescurrentHunkIndexfor navigation:currentHunkIndex)currentHunkIndex)Missing: Spacebar key binding that allows default scroll behavior without affecting state
Additional Context
Test Scenario
A reproducible test case would:
currentHunkIndexremains at 2 (third change, 0-indexed)