Skip to content

Commit 82a6a91

Browse files
committed
fix: prevent scroll snapback when using Space/PgUp/PgDown
The useLayoutEffect that scrolls the selected hunk into view was firing whenever selectedEstimatedScrollTop changed, which happens during normal scrolling when agent notes are visible (metrics recalculate as viewport changes). Fix: Track previous selectedAnchorId and only auto-scroll when the selection actually changes, not when layout metrics update during free scrolling. Closes scroll snapback issue with Space, PageUp, PageDown keys.
1 parent f402db8 commit 82a6a91

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ui/components/panes/DiffPane.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,20 @@ export function DiffPane({
305305
return top;
306306
}, [estimatedBodyHeights, sectionMetrics, selectedFile, selectedFileIndex, selectedHunkIndex]);
307307

308+
// Track the previous selected anchor to detect actual selection changes
309+
const prevSelectedAnchorIdRef = useRef<string | null>(null);
310+
308311
useLayoutEffect(() => {
309312
if (!selectedAnchorId) {
313+
prevSelectedAnchorIdRef.current = null;
314+
return;
315+
}
316+
317+
// Only auto-scroll when the selection actually changes, not when metrics update during scrolling
318+
const isSelectionChange = prevSelectedAnchorIdRef.current !== selectedAnchorId;
319+
prevSelectedAnchorIdRef.current = selectedAnchorId;
320+
321+
if (!isSelectionChange) {
310322
return;
311323
}
312324

0 commit comments

Comments
 (0)