From e93c65f9ed7f5b0ad5deed87206fe2ea4ff65bd4 Mon Sep 17 00:00:00 2001 From: Wooseong Kim <2222333+innocarpe@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:07:48 +0900 Subject: [PATCH] fix(file-explorer): stop waiting to reveal paths the listing never shows (#41047) The explorer drops node_modules and .git from every listing page, so a reveal under them waited for a row that never appeared. The request stayed pending and auto-reveal ignored later editor tabs. getRevealTarget now cuts the reveal off at the first folder the listing filter rejects. A nested hidden folder selects the folder that holds it; one directly under the root clears the request. Hidden folders are never expanded or read. Fixes #41039 Co-authored-by: Neil --- .../navigation/file-explorer-paths.test.ts | 31 ++++++++++-- .../navigation/file-explorer-paths.ts | 35 +++++++------- .../navigation/useFileExplorerReveal.ts | 48 +++++++------------ 3 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.test.ts b/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.test.ts index 1034fda4795..e95d83f5759 100644 --- a/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.test.ts +++ b/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.test.ts @@ -1,8 +1,31 @@ import { expect, it } from 'vitest' -import { getRevealTargetPath } from './file-explorer-paths' +import { getRevealTarget } from './file-explorer-paths' it('re-spells a forward-slash reveal target to match a Windows root', () => { - expect(getRevealTargetPath('C:\\Projects\\other', 'C:/Projects/other/docs/api')).toBe( - 'C:\\Projects\\other\\docs\\api' - ) + expect(getRevealTarget('C:\\Projects\\other', 'C:/Projects/other/docs/api')).toEqual({ + targetPath: 'C:\\Projects\\other\\docs\\api', + ancestorDirs: ['C:\\Projects\\other\\docs'] + }) +}) + +it('keeps a POSIX folder whose name contains a backslash as one listed segment', () => { + expect(getRevealTarget('/repo', '/repo/foo\\node_modules/index.js')).toEqual({ + targetPath: '/repo/foo\\node_modules/index.js', + ancestorDirs: ['/repo/foo\\node_modules'] + }) +}) + +it('has nothing to reveal under a node_modules the root holds', () => { + expect(getRevealTarget('/repo', '/repo/node_modules/pkg/index.js')).toBeNull() +}) + +it('stops at the folder holding a nested .git', () => { + expect(getRevealTarget('/repo', '/repo/src/app/.git/objects/pack')).toEqual({ + targetPath: '/repo/src/app', + ancestorDirs: ['/repo/src'] + }) +}) + +it('returns null for a path outside the root', () => { + expect(getRevealTarget('/repo', '/other/file.ts')).toBeNull() }) diff --git a/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.ts b/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.ts index 036b3181eef..6177681ccb3 100644 --- a/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.ts +++ b/src/renderer/src/components/right-sidebar/file-explorer/navigation/file-explorer-paths.ts @@ -4,31 +4,32 @@ import { relativePathInsideRoot, splitPathSegments } from '../../../../../../shared/cross-platform-path' +import { shouldIncludeFileExplorerEntry } from '../tree/file-explorer-entries' export function isPathEqualOrDescendant(candidatePath: string, targetPath: string): boolean { return isPathInsideOrEqual(targetPath, candidatePath) } -export function getRevealAncestorDirs(worktreePath: string, filePath: string): string[] | null { - const relativePath = relativePathInsideRoot(worktreePath, filePath) +/** + * Paths are re-spelled on the root's separators so they match rows. The explorer never lists + * node_modules or .git, so a reveal below one stops at the folder holding it. + */ +export function getRevealTarget( + rootPath: string, + filePath: string +): { targetPath: string; ancestorDirs: string[] } | null { + const relativePath = relativePathInsideRoot(rootPath, filePath) if (relativePath === null) { return null } - - const segments = splitPathSegments(relativePath, worktreePath) const ancestorDirs: string[] = [] - let currentPath = worktreePath - - for (const segment of segments.slice(0, -1)) { - currentPath = joinPath(currentPath, segment) - ancestorDirs.push(currentPath) + for (const name of splitPathSegments(relativePath, rootPath).slice(0, -1)) { + if (!shouldIncludeFileExplorerEntry({ name, isDirectory: true, isSymlink: false })) { + // When the root holds it there is nothing to select: the root is not a row. + const holderPath = ancestorDirs.pop() + return holderPath === undefined ? null : { targetPath: holderPath, ancestorDirs } + } + ancestorDirs.push(joinPath(ancestorDirs.at(-1) ?? rootPath, name)) } - - return ancestorDirs -} - -/** Rows join on the root's separators, so a reveal target spelled another way must be re-spelled to match. */ -export function getRevealTargetPath(rootPath: string, filePath: string): string { - const relativePath = relativePathInsideRoot(rootPath, filePath) - return relativePath === null ? filePath : joinPath(rootPath, relativePath) + return { targetPath: joinPath(rootPath, relativePath), ancestorDirs } } diff --git a/src/renderer/src/components/right-sidebar/file-explorer/navigation/useFileExplorerReveal.ts b/src/renderer/src/components/right-sidebar/file-explorer/navigation/useFileExplorerReveal.ts index 1d8480ba911..6a170eac8f5 100644 --- a/src/renderer/src/components/right-sidebar/file-explorer/navigation/useFileExplorerReveal.ts +++ b/src/renderer/src/components/right-sidebar/file-explorer/navigation/useFileExplorerReveal.ts @@ -5,7 +5,7 @@ import { getRelativePathInsideRoot } from '@/lib/path' import { getExplorerDisplayDepth } from './file-explorer-display-root' import { FILE_EXPLORER_FULL_ROOT } from '../../../../../../shared/file-listing/file-explorer-display-root' import { useAppStore } from '@/store/index' -import { getRevealAncestorDirs, getRevealTargetPath } from './file-explorer-paths' +import { getRevealTarget } from './file-explorer-paths' import type { DirCache } from '../tree/file-explorer-types' import type { FileExplorerRowProjection } from '../tree/file-explorer-row-projection' import { fileExplorerRevealDirToReadOn } from '../tree/file-explorer-dir-pages' @@ -77,7 +77,7 @@ export function useFileExplorerReveal({ } }, [cancelRevealScroll, flashTimeoutRef]) - const pendingRevealAncestorDirs = useMemo(() => { + const pendingRevealTarget = useMemo(() => { if ( !pendingExplorerReveal || !activeWorktreeId || @@ -90,7 +90,7 @@ export function useFileExplorerReveal({ if (getRelativePathInsideRoot(pendingExplorerReveal.filePath, worktreePath) === null) { return null } - return getRevealAncestorDirs(displayRootPath ?? worktreePath, pendingExplorerReveal.filePath) + return getRevealTarget(displayRootPath ?? worktreePath, pendingExplorerReveal.filePath) }, [activeWorktreeId, pendingExplorerReveal, worktreePath, displayRootPath]) useEffect(() => { @@ -114,17 +114,18 @@ export function useFileExplorerReveal({ } return } - if (!pendingRevealAncestorDirs) { + if (!pendingRevealTarget) { clearPendingExplorerReveal() return } + const { ancestorDirs } = pendingRevealTarget useAppStore.setState((state) => { const currentExpanded = state.expandedDirs[activeWorktreeId] ?? new Set() const nextExpanded = new Set(currentExpanded) let changed = false - for (const dirPath of pendingRevealAncestorDirs) { + for (const dirPath of ancestorDirs) { if (!nextExpanded.has(dirPath)) { nextExpanded.add(dirPath) changed = true @@ -152,10 +153,10 @@ export function useFileExplorerReveal({ return } - for (let depth = 0; depth < pendingRevealAncestorDirs.length; depth += 1) { + for (const dirPath of ancestorDirs) { const ancestorLoaded = await loadDir( - pendingRevealAncestorDirs[depth], - getExplorerDisplayDepth(worktreePath, pendingRevealAncestorDirs[depth]) - 1 + dirPath, + getExplorerDisplayDepth(worktreePath, dirPath) - 1 ) if (!ancestorLoaded) { return @@ -167,7 +168,7 @@ export function useFileExplorerReveal({ clearPendingExplorerReveal, loadDir, pendingExplorerReveal, - pendingRevealAncestorDirs, + pendingRevealTarget, onRevealOutsideRoot, worktreePath, displayRootPath @@ -179,26 +180,16 @@ export function useFileExplorerReveal({ !activeWorktreeId || pendingExplorerReveal.worktreeId !== activeWorktreeId || !worktreePath || - !pendingRevealAncestorDirs + !pendingRevealTarget ) { return } - const targetPath = getRevealTargetPath( - displayRootPath ?? worktreePath, - pendingExplorerReveal.filePath - ) - const parentDirPath = - pendingRevealAncestorDirs.length > 0 - ? pendingRevealAncestorDirs.at(-1)! - : (displayRootPath ?? worktreePath) + const { targetPath, ancestorDirs } = pendingRevealTarget + const parentDirPath = ancestorDirs.at(-1) ?? displayRootPath ?? worktreePath const parentDirCache = dirCache[parentDirPath] - const missingExpandedAncestor = pendingRevealAncestorDirs.find( - (dirPath) => !expanded.has(dirPath) - ) - const missingAncestor = pendingRevealAncestorDirs.find( - (dirPath) => !rowProjection.hasPath(dirPath) - ) + const missingExpandedAncestor = ancestorDirs.find((dirPath) => !expanded.has(dirPath)) + const missingAncestor = ancestorDirs.find((dirPath) => !rowProjection.hasPath(dirPath)) const rootStillLoading = !rootCache || loadingDirPaths.has(displayRootPath ?? worktreePath) const parentDirStillLoading = parentDirPath === (displayRootPath ?? worktreePath) @@ -211,16 +202,13 @@ export function useFileExplorerReveal({ !rootStillLoading && (rootCache?.error || parentDirCache?.error || - pendingRevealAncestorDirs.some((path) => dirCache[path]?.error)) + ancestorDirs.some((path) => dirCache[path]?.error)) ) { clearPendingExplorerReveal() return } const readOn = loadMoreDir - ? fileExplorerRevealDirToReadOn(dirCache, rowProjection, [ - ...pendingRevealAncestorDirs, - targetPath - ]) + ? fileExplorerRevealDirToReadOn(dirCache, rowProjection, [...ancestorDirs, targetPath]) : null if (readOn !== null) { if (!loadingDirPaths.has(readOn)) { @@ -280,7 +268,7 @@ export function useFileExplorerReveal({ loadMoreDir, loadingDirPaths, pendingExplorerReveal, - pendingRevealAncestorDirs, + pendingRevealTarget, rowProjection, rootCache, setFlashingPath,