mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: jump to items from search result
This doesn't cause the previous redirect bug :)
This commit is contained in:
parent
b08cc31940
commit
59fffaf004
2 changed files with 13 additions and 6 deletions
|
|
@ -180,15 +180,16 @@ function ListView({
|
|||
visibleNodes,
|
||||
}: ListViewProps & Pick<Props, 'metaData'> & Pick<ConnectorState, 'expandTo'>) {
|
||||
const listRef = React.useRef<FixedSizeList>(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}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue