From f05a667743fabb19f122eaa14f6323c49eeff2cc Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:44:21 +0000 Subject: [PATCH] fix(web): scope root reveal selection sync Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com> --- .../src/components/files/FileBrowserPanel.tsx | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/files/FileBrowserPanel.tsx b/apps/web/src/components/files/FileBrowserPanel.tsx index 41274988e7..99ce2975ce 100644 --- a/apps/web/src/components/files/FileBrowserPanel.tsx +++ b/apps/web/src/components/files/FileBrowserPanel.tsx @@ -144,15 +144,27 @@ export default function FileBrowserPanel({ const treeSelectionPathRef = useRef(null); const handledRevealRef = useRef<{ path: string; revealId: number } | null>(null); const handledBreadcrumbRevealRef = useRef<{ path: string; revealId: number } | null>(null); - const suppressSelectedPathScrollRef = useRef(breadcrumbRevealPath === ""); - if ( - breadcrumbRevealPath === "" && - selectedPath && - (handledRevealRef.current?.path !== selectedPath || - handledRevealRef.current.revealId !== selectedPathRevealId) - ) { - suppressSelectedPathScrollRef.current = true; - } + const suppressedSelectedPathRef = useRef<{ path: string; revealId: number } | null>(null); + const capturedRootRevealIdRef = useRef(null); + + useEffect(() => { + if (breadcrumbRevealPath !== "") { + if (breadcrumbRevealPath !== null) suppressedSelectedPathRef.current = null; + return; + } + if (capturedRootRevealIdRef.current === breadcrumbRevealId) return; + capturedRootRevealIdRef.current = breadcrumbRevealId; + const handledReveal = handledRevealRef.current; + if ( + selectedPath && + (handledReveal?.path !== selectedPath || handledReveal.revealId !== selectedPathRevealId) + ) { + suppressedSelectedPathRef.current = { + path: selectedPath, + revealId: breadcrumbRevealId, + }; + } + }, [breadcrumbRevealId, breadcrumbRevealPath, selectedPath, selectedPathRevealId]); // The tree renders rows in shadow DOM and its anchor rect is unreliable, so // capture the right-click position ourselves; contextmenu is a composed @@ -298,7 +310,7 @@ export default function FileBrowserPanel({ useEffect(() => { if (!selectedPath) { handledRevealRef.current = null; - suppressSelectedPathScrollRef.current = false; + suppressedSelectedPathRef.current = null; return; } const revealRequest = { path: selectedPath, revealId: selectedPathRevealId }; @@ -328,10 +340,10 @@ export default function FileBrowserPanel({ return; } - if (suppressSelectedPathScrollRef.current) { + if (suppressedSelectedPathRef.current?.path === selectedPath) { treeSelectionPathRef.current = null; handledRevealRef.current = revealRequest; - suppressSelectedPathScrollRef.current = false; + suppressedSelectedPathRef.current = null; syncingSelectionRef.current = true; const segments = selectedPath.split("/"); let ancestorPath = ""; @@ -340,6 +352,9 @@ export default function FileBrowserPanel({ const item = model.getItem(`${ancestorPath}/`) ?? model.getItem(ancestorPath); if (item && "expand" in item) item.expand(); } + for (const path of model.getSelectedPaths()) { + model.getItem(path)?.deselect(); + } selectedItem.select(); queueMicrotask(() => { syncingSelectionRef.current = false;