From 94a2fd88cee92c9f5dc9b931643f2dd8fa0c3f2c 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:05:58 +0000 Subject: [PATCH] fix(web): preserve selection on root reveal Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com> --- .../check-run-agents/ui-consistency.md | 2 +- .../src/components/files/FileBrowserPanel.tsx | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.macroscope/check-run-agents/ui-consistency.md b/.macroscope/check-run-agents/ui-consistency.md index 5f24014a8b..c2c5900ad5 100644 --- a/.macroscope/check-run-agents/ui-consistency.md +++ b/.macroscope/check-run-agents/ui-consistency.md @@ -59,7 +59,7 @@ The goal is not to minimize CSS or class counts at any cost. The goal is to put - Preserve runtime top and bottom overflow state. Do not replace dynamic fades with an always-on static mask. - Preserve fade geometry and keep the native scrollbar lane opaque so the track and thumb stay visible and usable. A visually similar mask that fades the scrollbar is a regression. - For path-driven tree actions with flattened directory rows, do not assume that every registered item path is currently visible. Resolve the target through the tree's visible projection before selecting, focusing, or scrolling, and verify intermediate directory actions against a real flattened chain. -- Treat external tree-reveal requests as one-shot events: resolve and validate the visible target without mutating search, focus, or selection, then acknowledge or clear the request after success so component remounts cannot replay stale navigation. +- Treat external tree-reveal requests as one-shot events: resolve and validate the visible target without mutating search, focus, or selection, then acknowledge or clear the request after success so component remounts cannot replay stale navigation. A project-root reveal should scroll the tree viewport itself and preserve the current selected item; raw entry order is not visible row order. - Verify actual scroll behavior when changing virtualizers, masks, overflow ownership, or scrollbar selectors. Source-level class comparison is not enough. ## Visual and layout preservation diff --git a/apps/web/src/components/files/FileBrowserPanel.tsx b/apps/web/src/components/files/FileBrowserPanel.tsx index b161de2d8f..48ba7fd95f 100644 --- a/apps/web/src/components/files/FileBrowserPanel.tsx +++ b/apps/web/src/components/files/FileBrowserPanel.tsx @@ -361,13 +361,13 @@ export default function FileBrowserPanel({ ? `${breadcrumbRevealPath}/` : breadcrumbRevealPath; const item = itemPath ? (model.getItem(itemPath) ?? model.getItem(breadcrumbRevealPath)) : null; - const firstEntry = entries[0]; - const rootItemPath = firstEntry - ? firstEntry.kind === "directory" - ? visibleDirectoryTreePath(entries, firstEntry.path) - : firstEntry.path - : null; - if ((breadcrumbRevealPath && !item) || (!breadcrumbRevealPath && !rootItemPath)) return; + const rootScrollContainer = + breadcrumbRevealPath === "" + ? model + .getFileTreeContainer() + ?.shadowRoot?.querySelector("[data-file-tree-virtualized-scroll]") + : null; + if ((breadcrumbRevealPath && !item) || (!breadcrumbRevealPath && !rootScrollContainer)) return; const visibleItemPath = itemPath ? entryKind === "directory" @@ -379,8 +379,10 @@ export default function FileBrowserPanel({ handledBreadcrumbRevealRef.current = revealRequest; syncingSelectionRef.current = true; model.closeSearch(); - for (const path of model.getSelectedPaths()) { - model.getItem(path)?.deselect(); + if (visibleItemPath) { + for (const path of model.getSelectedPaths()) { + model.getItem(path)?.deselect(); + } } const segments = breadcrumbRevealPath.split("/").filter(Boolean); @@ -394,8 +396,8 @@ export default function FileBrowserPanel({ if (visibleItemPath) { model.getItem(visibleItemPath)?.select(); model.scrollToPath(visibleItemPath, { focus: true, offset: "center" }); - } else if (rootItemPath) { - model.scrollToPath(rootItemPath, { focus: true, offset: "top" }); + } else if (rootScrollContainer) { + rootScrollContainer.scrollTop = 0; } onBreadcrumbRevealHandled(breadcrumbRevealId); queueMicrotask(() => { @@ -408,7 +410,6 @@ export default function FileBrowserPanel({ entryKinds, model, onBreadcrumbRevealHandled, - treePaths, ]); // Tag tree drags with the composer mention payload. The row is read from