Sync active hunks to mouse scrolling and prefetch diff highlighting#172
Conversation
Greptile SummaryThis PR adds two related features: (1) syncing the active file/hunk selection as mouse-wheel scrolling changes the viewport center, and (2) prefetching syntax highlighting for files approaching the viewport so code is highlighted before it becomes visible. The viewport selection sync is gated by a ref-based 120 ms debounce ( Key changes:
Confidence Score: 4/5Safe to merge; a single P2 naming issue is the only finding Score of 4 reflects one P2 style issue (loop variable 'layout' shadowing the outer layout prop on DiffPane.tsx line 418) that does not affect runtime behaviour but should be cleaned up for readability. The mouse-scroll debounce logic, viewport-centred hunk selection, and prefetch cache design are all sound and covered by tests. src/ui/components/panes/DiffPane.tsx — loop variable 'layout' shadows the outer layout prop on line 418 Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant DiffPane
participant mouseRef as mouseScrollSelectionSyncActiveRef
participant timer as 120ms Debounce Timer
participant viewSel as findViewportCenteredHunkTarget
participant App
participant cache as SHARED_HIGHLIGHTED_DIFF_CACHE
User->>DiffPane: onMouseScroll
DiffPane->>mouseRef: set true
DiffPane->>timer: reset debounce
timer-->>mouseRef: set false (after 120 ms)
Note over DiffPane: scrollViewport.top changes
DiffPane->>viewSel: findViewportCenteredHunkTarget()
viewSel-->>DiffPane: { fileId, hunkIndex }
DiffPane->>DiffPane: suppressNextSelectionAutoScrollRef = true
DiffPane->>App: onViewportCenteredHunkChange(fileId, hunkIndex)
App-->>DiffPane: re-render with new selectedFileId / selectedHunkIndex
Note over DiffPane: selection auto-scroll useLayoutEffect fires
DiffPane->>mouseRef: check → true → skip auto-scroll
Note over DiffPane: highlightPrefetchFileIds recomputed
DiffPane->>cache: prefetchHighlightedDiff(file, appearance)
cache-->>DiffPane: cache miss → loadHighlightedDiff() started
Note over cache: result stored on resolve
DiffPane->>DiffPane: shouldLoadHighlight passed to DiffSection
|
Summary
Testing
This PR description was generated by Pi using GPT-5