From 48f1f365b237256cdd4c9e3634e8b97339885ac9 Mon Sep 17 00:00:00 2001 From: Ignacio Cervino Date: Mon, 19 Jan 2026 01:42:31 -0300 Subject: [PATCH 1/4] fix: sync git diff selection --- src/features/git/components/GitDiffViewer.tsx | 36 ++++++++++++++----- .../workspaces/hooks/useWorkspaceSelection.ts | 7 ++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/features/git/components/GitDiffViewer.tsx b/src/features/git/components/GitDiffViewer.tsx index cef9dbfa3..101d6bd84 100644 --- a/src/features/git/components/GitDiffViewer.tsx +++ b/src/features/git/components/GitDiffViewer.tsx @@ -127,6 +127,8 @@ export function GitDiffViewer({ const listRef = useRef(null); const lastScrolledPathRef = useRef(null); const activePathRef = useRef(null); + const ignoreActivePathUntilRef = useRef(0); + const lastSelectionFromScrollRef = useRef(false); const poolOptions = useMemo(() => ({ workerFactory }), []); const highlighterOptions = useMemo( () => ({ theme: { dark: "pierre-dark", light: "pierre-light" } }), @@ -163,13 +165,18 @@ export function GitDiffViewer({ if (!selectedPath) { return; } - if (lastScrolledPathRef.current === selectedPath) { + const shouldSkipScroll = + lastSelectionFromScrollRef.current && + lastScrolledPathRef.current === selectedPath; + if (shouldSkipScroll) { + lastSelectionFromScrollRef.current = false; return; } const index = indexByPath.get(selectedPath); if (index === undefined) { return; } + ignoreActivePathUntilRef.current = Date.now() + 250; rowVirtualizer.scrollToIndex(index, { align: "start" }); lastScrolledPathRef.current = selectedPath; }, [selectedPath, indexByPath, rowVirtualizer]); @@ -187,26 +194,37 @@ export function GitDiffViewer({ const updateActivePath = () => { frameId = null; + if (Date.now() < ignoreActivePathUntilRef.current) { + return; + } const items = rowVirtualizer.getVirtualItems(); if (!items.length) { return; } const scrollTop = container.scrollTop; - const targetOffset = scrollTop + 8; - let activeItem = items[0]; - for (const item of items) { - if (item.start <= targetOffset) { - activeItem = item; - } else { - break; + const isAtBottom = + scrollTop + container.clientHeight >= container.scrollHeight - 4; + let nextPath: string | undefined; + if (isAtBottom) { + nextPath = diffs[diffs.length - 1]?.path; + } else { + const targetOffset = scrollTop + 8; + let activeItem = items[0]; + for (const item of items) { + if (item.start <= targetOffset) { + activeItem = item; + } else { + break; + } } + nextPath = diffs[activeItem.index]?.path; } - const nextPath = diffs[activeItem.index]?.path; if (!nextPath || nextPath === activePathRef.current) { return; } activePathRef.current = nextPath; lastScrolledPathRef.current = nextPath; + lastSelectionFromScrollRef.current = true; onActivePathChange(nextPath); }; diff --git a/src/features/workspaces/hooks/useWorkspaceSelection.ts b/src/features/workspaces/hooks/useWorkspaceSelection.ts index d559a0b2f..1810b82ae 100644 --- a/src/features/workspaces/hooks/useWorkspaceSelection.ts +++ b/src/features/workspaces/hooks/useWorkspaceSelection.ts @@ -31,11 +31,11 @@ export function useWorkspaceSelection({ }: UseWorkspaceSelectionOptions): UseWorkspaceSelectionResult { const exitDiffView = useCallback(() => { setCenterMode("chat"); - setSelectedDiffPath(null); - }, [setCenterMode, setSelectedDiffPath]); + }, [setCenterMode]); const selectWorkspace = useCallback( (workspaceId: string) => { + setSelectedDiffPath(null); const target = workspaces.find((entry) => entry.id === workspaceId); if (target?.settings.sidebarCollapsed) { void updateWorkspaceSettings(workspaceId, { @@ -59,11 +59,12 @@ export function useWorkspaceSelection({ const selectHome = useCallback(() => { exitDiffView(); + setSelectedDiffPath(null); setActiveWorkspaceId(null); if (isCompact) { setActiveTab("projects"); } - }, [exitDiffView, isCompact, setActiveTab, setActiveWorkspaceId]); + }, [exitDiffView, isCompact, setActiveTab, setActiveWorkspaceId, setSelectedDiffPath]); return { exitDiffView, selectWorkspace, selectHome }; } From 0e786265086b8e75a04bfaaf4bcb65ae252347d7 Mon Sep 17 00:00:00 2001 From: Ignacio Cervino Date: Mon, 19 Jan 2026 01:45:32 -0300 Subject: [PATCH 2/4] fix: tidy git diff selection deps --- src/features/workspaces/hooks/useWorkspaceSelection.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/features/workspaces/hooks/useWorkspaceSelection.ts b/src/features/workspaces/hooks/useWorkspaceSelection.ts index 1810b82ae..8db30bc18 100644 --- a/src/features/workspaces/hooks/useWorkspaceSelection.ts +++ b/src/features/workspaces/hooks/useWorkspaceSelection.ts @@ -52,6 +52,7 @@ export function useWorkspaceSelection({ isCompact, setActiveTab, setActiveWorkspaceId, + setSelectedDiffPath, updateWorkspaceSettings, workspaces, ], From 6f0bfe6cc8a6e7b3be69feac0e1b3a59cae0fe38 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Mon, 19 Jan 2026 08:16:55 +0100 Subject: [PATCH 3/4] Update GitDiffViewer.tsx --- src/features/git/components/GitDiffViewer.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/features/git/components/GitDiffViewer.tsx b/src/features/git/components/GitDiffViewer.tsx index 101d6bd84..778c64150 100644 --- a/src/features/git/components/GitDiffViewer.tsx +++ b/src/features/git/components/GitDiffViewer.tsx @@ -202,7 +202,9 @@ export function GitDiffViewer({ return; } const scrollTop = container.scrollTop; + const canScroll = container.scrollHeight > container.clientHeight; const isAtBottom = + canScroll && scrollTop + container.clientHeight >= container.scrollHeight - 4; let nextPath: string | undefined; if (isAtBottom) { From 40dbd42527ddab17cbd2ebc7c10437499aeb04f8 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Mon, 19 Jan 2026 08:21:21 +0100 Subject: [PATCH 4/4] Update useWorkspaceSelection.ts --- src/features/workspaces/hooks/useWorkspaceSelection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/features/workspaces/hooks/useWorkspaceSelection.ts b/src/features/workspaces/hooks/useWorkspaceSelection.ts index 8db30bc18..b5316acbf 100644 --- a/src/features/workspaces/hooks/useWorkspaceSelection.ts +++ b/src/features/workspaces/hooks/useWorkspaceSelection.ts @@ -31,7 +31,8 @@ export function useWorkspaceSelection({ }: UseWorkspaceSelectionOptions): UseWorkspaceSelectionResult { const exitDiffView = useCallback(() => { setCenterMode("chat"); - }, [setCenterMode]); + setSelectedDiffPath(null); + }, [setCenterMode, setSelectedDiffPath]); const selectWorkspace = useCallback( (workspaceId: string) => {