Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 1d3f6ba

Browse files
AnshulMalikjasonLaster
authored andcommitted
[Sources] Auto expand path of selected source (#5716)
* auto expand path of selected source * add test
1 parent 774577c commit 1d3f6ba

5 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/components/PrimaryPanes/SourcesTree.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ class SourcesTree extends Component<Props, State> {
370370
const treeProps = {
371371
autoExpandAll: false,
372372
autoExpandDepth: expanded ? 0 : 1,
373+
autoExpandOnHighlight: true,
373374
expanded,
374375
getChildren: item => (nodeHasChildren(item) ? item.contents : []),
375376
getParent: item => parentMap.get(item),

src/components/shared/ManagedTree.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type Item = {
1717
type Props = {
1818
autoExpandAll: boolean,
1919
autoExpandDepth: number,
20+
autoExpandOnHighlight?: boolean,
2021
getChildren: Object => Object[],
2122
getPath: (Object, index?: number) => string,
2223
getParent: Item => any,
@@ -123,11 +124,20 @@ class ManagedTree extends Component<Props, State> {
123124
if (expanded.has(this.props.getPath(highlightItems[0]))) {
124125
this.focusItem(highlightItems[0]);
125126
} else {
126-
// Look at folders starting from the top-level until finds a
127-
// closed folder and highlights this folder
128-
const index = highlightItems
129-
.reverse()
130-
.findIndex(item => !expanded.has(this.props.getPath(item)));
127+
// Look at folders starting from the top-level and expand all the items
128+
// which lie in the path of the item to be highlighted
129+
highlightItems.reverse();
130+
let index = highlightItems.findIndex(
131+
item => !expanded.has(this.props.getPath(item))
132+
);
133+
134+
if (this.props.autoExpandOnHighlight) {
135+
while (index < highlightItems.length - 1) {
136+
this.setExpanded(highlightItems[index], true, false);
137+
index++;
138+
}
139+
}
140+
131141
this.focusItem(highlightItems[index]);
132142
}
133143
}

src/components/tests/__snapshots__/SourcesTree.spec.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,
1111
<ManagedTree
1212
autoExpandAll={false}
1313
autoExpandDepth={0}
14+
autoExpandOnHighlight={true}
1415
expanded={
1516
Array [
1617
"four.js",
@@ -44,6 +45,7 @@ exports[`SourcesTree Should show the tree with nothing expanded 1`] = `
4445
<ManagedTree
4546
autoExpandAll={false}
4647
autoExpandDepth={1}
48+
autoExpandOnHighlight={true}
4749
getChildren={[Function]}
4850
getParent={[Function]}
4951
getPath={[Function]}
@@ -70,6 +72,7 @@ exports[`SourcesTree When loading initial source Shows the tree with one.js, two
7072
<ManagedTree
7173
autoExpandAll={false}
7274
autoExpandDepth={0}
75+
autoExpandOnHighlight={true}
7376
expanded={
7477
Array [
7578
"one.js",

src/test/mochitest/browser_dbg-asm.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ add_task(async function() {
99

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

12-
// Expand nodes and make sure more sources appear.
13-
is(findAllElements(dbg, "sourceNodes").length, 2);
14-
15-
await clickElement(dbg, "sourceDirectoryLabel", 2);
1612
is(findAllElements(dbg, "sourceNodes").length, 4);
1713

1814
await selectSource(dbg, "asm.js");

src/test/mochitest/browser_dbg-sources.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ function getLabel(dbg, index) {
2222
.replace(/^[\s\u200b]*/g, "");
2323
}
2424

25+
add_task(async function() {
26+
const dbg = await initDebugger("doc-sources.html");
27+
const { selectors: { getSelectedSource, getExpandedState }, getState } = dbg;
28+
29+
await waitForSources(dbg, "nested-source");
30+
await selectSource(dbg, "nested-source");
31+
32+
const expanded = getExpandedState(getState());
33+
34+
ok(
35+
expanded.has(
36+
`/example.com/browser/devtools/client/debugger/new/test/mochitest/examples/nested/nested/`
37+
),
38+
"Nodes in path are automatically expanded"
39+
);
40+
});
41+
2542
add_task(async function() {
2643
const dbg = await initDebugger("doc-sources.html");
2744
const { selectors: { getSelectedSource }, getState } = dbg;

0 commit comments

Comments
 (0)