diff --git a/src/components/PrimaryPanes/SourcesTree.js b/src/components/PrimaryPanes/SourcesTree.js index a7e095dabc..91a30963e9 100644 --- a/src/components/PrimaryPanes/SourcesTree.js +++ b/src/components/PrimaryPanes/SourcesTree.js @@ -370,6 +370,7 @@ class SourcesTree extends Component { const treeProps = { autoExpandAll: false, autoExpandDepth: expanded ? 0 : 1, + autoExpandOnHighlight: true, expanded, getChildren: item => (nodeHasChildren(item) ? item.contents : []), getParent: item => parentMap.get(item), diff --git a/src/components/shared/ManagedTree.js b/src/components/shared/ManagedTree.js index 787df2a993..fce9a668a5 100644 --- a/src/components/shared/ManagedTree.js +++ b/src/components/shared/ManagedTree.js @@ -17,6 +17,7 @@ export type Item = { type Props = { autoExpandAll: boolean, autoExpandDepth: number, + autoExpandOnHighlight?: boolean, getChildren: Object => Object[], getPath: (Object, index?: number) => string, getParent: Item => any, @@ -123,11 +124,20 @@ class ManagedTree extends Component { if (expanded.has(this.props.getPath(highlightItems[0]))) { this.focusItem(highlightItems[0]); } else { - // Look at folders starting from the top-level until finds a - // closed folder and highlights this folder - const index = highlightItems - .reverse() - .findIndex(item => !expanded.has(this.props.getPath(item))); + // Look at folders starting from the top-level and expand all the items + // which lie in the path of the item to be highlighted + highlightItems.reverse(); + let index = highlightItems.findIndex( + item => !expanded.has(this.props.getPath(item)) + ); + + if (this.props.autoExpandOnHighlight) { + while (index < highlightItems.length - 1) { + this.setExpanded(highlightItems[index], true, false); + index++; + } + } + this.focusItem(highlightItems[index]); } } diff --git a/src/components/tests/__snapshots__/SourcesTree.spec.js.snap b/src/components/tests/__snapshots__/SourcesTree.spec.js.snap index c3d58b4ca9..b29bf9d03e 100644 --- a/src/components/tests/__snapshots__/SourcesTree.spec.js.snap +++ b/src/components/tests/__snapshots__/SourcesTree.spec.js.snap @@ -11,6 +11,7 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,