diff --git a/src/components/FileExplorer.tsx b/src/components/FileExplorer.tsx index 13bba7f..dd2a2d7 100644 --- a/src/components/FileExplorer.tsx +++ b/src/components/FileExplorer.tsx @@ -180,15 +180,16 @@ function ListView({ visibleNodes, }: ListViewProps & Pick & Pick) { const listRef = React.useRef(null) - const { focusedNode, nodes } = visibleNodes + // the change of depths indicates switch into/from search state React.useEffect(() => { + const { focusedNode, nodes } = visibleNodes if (listRef.current && focusedNode?.path) { const index = nodes.findIndex(node => node.path === focusedNode.path) if (index !== -1) { listRef.current.scrollToItem(index, 'smart') } } - }, [focusedNode?.path]) + }, [visibleNodes]) // For some reason, removing the deps array above results in bug: // If scroll fast and far, then clicking on items would result in redirect // Not know the reason :( @@ -215,7 +216,7 @@ function ListView({ ref={listRef} itemKey={(index, { visibleNodes }) => visibleNodes?.nodes[index]?.path} itemData={itemData} - itemCount={nodes.length} + itemCount={visibleNodes.nodes.length} itemSize={36} height={height} width={width} diff --git a/src/utils/VisibleNodesGenerator.ts b/src/utils/VisibleNodesGenerator.ts index 753587a..48a2516 100644 --- a/src/utils/VisibleNodesGenerator.ts +++ b/src/utils/VisibleNodesGenerator.ts @@ -284,10 +284,16 @@ class FlattenLayer extends CompressLayer { await traverse( [rootNode], async node => { - const match = path.startsWith(node.path) - if (node.path && match) { + const overflowChar = node.path[path.length + 1] + const match = path.startsWith(node.path) && (overflowChar === '/' || !overflowChar) + if (node.path) { // rootNode.path === '' - await this.$setExpand(node, true) + if (match) { + if (node.path === path) { + // do not wait for expansion for the exact node as that will block "jumping from search" + this.$setExpand(node, true) + } else await this.$setExpand(node, true) + } } return match },