Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/PrimaryPanes/SourcesTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class SourcesTree extends Component<Props, State> {
const treeProps = {
autoExpandAll: false,
autoExpandDepth: expanded ? 0 : 1,
autoExpandOnHighlight: true,
expanded,
getChildren: item => (nodeHasChildren(item) ? item.contents : []),
getParent: item => parentMap.get(item),
Expand Down
20 changes: 15 additions & 5 deletions src/components/shared/ManagedTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -123,11 +124,20 @@ class ManagedTree extends Component<Props, State> {
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]);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/tests/__snapshots__/SourcesTree.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,
<ManagedTree
autoExpandAll={false}
autoExpandDepth={0}
autoExpandOnHighlight={true}
expanded={
Array [
"four.js",
Expand Down Expand Up @@ -44,6 +45,7 @@ exports[`SourcesTree Should show the tree with nothing expanded 1`] = `
<ManagedTree
autoExpandAll={false}
autoExpandDepth={1}
autoExpandOnHighlight={true}
getChildren={[Function]}
getParent={[Function]}
getPath={[Function]}
Expand All @@ -70,6 +72,7 @@ exports[`SourcesTree When loading initial source Shows the tree with one.js, two
<ManagedTree
autoExpandAll={false}
autoExpandDepth={0}
autoExpandOnHighlight={true}
expanded={
Array [
"one.js",
Expand Down
4 changes: 0 additions & 4 deletions src/test/mochitest/browser_dbg-asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ add_task(async function() {

await waitForSources(dbg, "doc-asm.html", "asm.js");

// Expand nodes and make sure more sources appear.
is(findAllElements(dbg, "sourceNodes").length, 2);

await clickElement(dbg, "sourceDirectoryLabel", 2);
is(findAllElements(dbg, "sourceNodes").length, 4);

await selectSource(dbg, "asm.js");
Expand Down
17 changes: 17 additions & 0 deletions src/test/mochitest/browser_dbg-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ function getLabel(dbg, index) {
.replace(/^[\s\u200b]*/g, "");
}

add_task(async function() {
const dbg = await initDebugger("doc-sources.html");
const { selectors: { getSelectedSource, getExpandedState }, getState } = dbg;

await waitForSources(dbg, "nested-source");
await selectSource(dbg, "nested-source");

const expanded = getExpandedState(getState());

ok(
expanded.has(
`/example.com/browser/devtools/client/debugger/new/test/mochitest/examples/nested/nested/`
),
"Nodes in path are automatically expanded"
);
});

add_task(async function() {
const dbg = await initDebugger("doc-sources.html");
const { selectors: { getSelectedSource }, getState } = dbg;
Expand Down