fix: blank file explorer when accessing non-exist file

This commit is contained in:
EnixCoda 2018-05-19 14:57:15 +08:00
parent b003f3acc3
commit 39c1653d90
2 changed files with 6 additions and 3 deletions

View file

@ -32,9 +32,11 @@ export default class List extends preact.Component {
this.tasksAfterRender.push(DOMHelper.focusSearchInput)
if (currentPath.length) {
const nodeExpandedTo = this.visibleNodesGenerator.expandTo(currentPath)
this.visibleNodesGenerator.focusNode(nodeExpandedTo)
const { nodes } = this.visibleNodesGenerator.visibleNodes
this.tasksAfterRender.push(() => DOMHelper.scrollToNodeElement(nodes.indexOf(nodeExpandedTo)))
if (nodeExpandedTo) {
this.visibleNodesGenerator.focusNode(nodeExpandedTo)
const { nodes } = this.visibleNodesGenerator.visibleNodes
this.tasksAfterRender.push(() => DOMHelper.scrollToNodeElement(nodes.indexOf(nodeExpandedTo)))
}
}
this.updateVisibleNodes()
}

View file

@ -97,6 +97,7 @@ export default class VisibleNodesGenerator {
for (const step of path) {
targetPath = rootNode.path ? `${rootNode.path}/${step}` : step
rootNode = rootNode.contents.find(node => node.path === targetPath)
if (!rootNode) return
this.setExpand(rootNode, true)
}
return rootNode