Skip to content

Commit 7bbb753

Browse files
authored
Rollup merge of #99373 - GuillaumeGomez:source-code-sidebar-tree-auto-expand, r=notriddle
Fix source code sidebar tree auto-expand Here is the bug: ![Screenshot from 2022-07-17 13-32-00](https://user-images.githubusercontent.com/3050060/179397712-bfb1c279-0ed2-4cb5-aef5-05741921bcc3.png) It was happening because as soon as we found the file (from the URL), every item following it was then opened, even if it wasn't supposed to. The GUI test ensures that it doesn't happen by adding two nested levels and ensuring only this path is "open". r? ``@notriddle``
2 parents f3a458f + 98bceb0 commit 7bbb753

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

Diff for: src/librustdoc/html/static/js/source-script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
3333
folders.className = "folders";
3434
if (elem.dirs) {
3535
for (const dir of elem.dirs) {
36-
if (createDirEntry(dir, folders, fullPath, hasFoundFile)) {
36+
if (createDirEntry(dir, folders, fullPath, false)) {
3737
dirEntry.open = true;
3838
hasFoundFile = true;
3939
}

Diff for: src/test/rustdoc-gui/sidebar-source-code.goml

+17-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,27 @@ click: (10, 10)
1616
wait-for: "html:not(.expanded)"
1717
assert: "nav.sidebar"
1818

19+
// Checking that only the path to the current file is "open".
20+
goto: file://|DOC_PATH|/src/lib2/another_folder/sub_mod/mod.rs.html
21+
// First we expand the sidebar again.
22+
click: (10, 10)
23+
// We wait for the sidebar to be expanded.
24+
wait-for-css: (".source-sidebar-expanded nav.sidebar", {"width": "300px"})
25+
assert: "//*[@class='dir-entry' and @open]/*[text()='lib2']"
26+
assert: "//*[@class='dir-entry' and @open]/*[text()='another_folder']"
27+
assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
28+
// Only "another_folder" should be "open" in "lib2".
29+
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
30+
// All other trees should be collapsed.
31+
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 5)
32+
1933
// We now switch to mobile mode.
2034
size: (600, 600)
21-
// We check that the sidebar has the expected width (0).
22-
assert-css: ("nav.sidebar", {"width": "0px"})
23-
// We expand the sidebar.
24-
click: "#sidebar-toggle"
25-
assert-css: (".source-sidebar-expanded nav.sidebar", {"width": "600px"})
35+
wait-for-css: (".source-sidebar-expanded nav.sidebar", {"width": "600px"})
2636
// We collapse the sidebar.
2737
click: (10, 10)
38+
// We check that the sidebar has the expected width (0).
39+
assert-css: ("nav.sidebar", {"width": "0px"})
2840
// We ensure that the class has been removed.
2941
assert-false: ".source-sidebar-expanded"
3042
assert: "nav.sidebar"

Diff for: src/test/rustdoc-gui/src/lib2/another_folder/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn another_fn() {}
2+
3+
pub mod sub_mod;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn subsubsub() {}

Diff for: src/test/rustdoc-gui/src/lib2/another_mod/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn tadam() {}

Diff for: src/test/rustdoc-gui/src/lib2/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
#![feature(doc_cfg)]
44

5+
pub mod another_folder;
6+
pub mod another_mod;
7+
58
pub mod module {
69
pub mod sub_module {
710
pub mod sub_sub_module {

0 commit comments

Comments
 (0)