Skip to content

Commit

Permalink
Rollup merge of #104967 - willcrichton:fix-scrape-examples, r=notriddle
Browse files Browse the repository at this point in the history
Fix UI issues with Rustdoc scrape-examples feature.

A few regressions have been introduced into scrape-examples in the last few months. This commit fixes those regressions:
* Help file was being loaded from the wrong place (introduced in f9e1f6f).
* CSS selector in JS has a typo (introduced in 1489718).
* Line numbers in scraped example code snippets are overflowing (not sure if this was ever fixed). Changing from flexbox to grid display fixed this issue.
  • Loading branch information
Yuki Okushi authored Dec 6, 2022
2 parents 226202d + f7a7059 commit 532fe7b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,9 @@ in storage.js
}

.scraped-example .code-wrapper .example-wrap {
flex: 1;
display: grid;
grid-template-columns: max-content auto;
width: 100%;
overflow-x: auto;
overflow-y: hidden;
margin-bottom: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/js/scrape-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
});
});

example.querySelector("next")
example.querySelector(".next")
.addEventListener("click", () => {
onChangeLoc(() => {
locIndex = (locIndex + 1) % locs.length;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ static_files! {
nanum_barun_gothic_license => "static/fonts/NanumBarunGothic-LICENSE.txt",
}

pub(crate) static SCRAPE_EXAMPLES_HELP_MD: &str = include_str!("static/js/scrape-examples.js");
pub(crate) static SCRAPE_EXAMPLES_HELP_MD: &str = include_str!("static/scrape-examples-help.md");
13 changes: 13 additions & 0 deletions src/test/rustdoc-gui/scrape-examples-button-focus.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"

store-property: (initialScrollTop, ".scraped-example-list > .scraped-example pre", "scrollTop")
focus: ".scraped-example-list > .scraped-example .next"
press-key: "Enter"
assert-property-false: (".scraped-example-list > .scraped-example pre", {
"scrollTop": |initialScrollTop|
})
focus: ".scraped-example-list > .scraped-example .prev"
press-key: "Enter"
assert-property: (".scraped-example-list > .scraped-example pre", {
"scrollTop": |initialScrollTop|
})

store-property: (smallOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight")
assert-property-false: (".scraped-example-list > .scraped-example pre", {
"scrollHeight": |smallOffsetHeight|
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc-gui/src/scrape_examples/examples/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ fn main() {
println!("hello world!");
println!("hello world!");
}
scrape_examples::test();
}

0 comments on commit 532fe7b

Please sign in to comment.