From 83ba42526fd859ab5605ada767f14c77b1dc2560 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Sat, 26 Nov 2022 21:39:39 -0600 Subject: [PATCH 1/3] Fix UI issues with Rustdoc scrape-examples feature. * Help file was being loaded from the wrong place. * CSS selector in JS has a typo. * Line numbers are overflowing, change to display: grid to fix. --- src/librustdoc/html/static/css/rustdoc.css | 4 +++- src/librustdoc/html/static/js/scrape-examples.js | 2 +- src/librustdoc/html/static_files.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 586462c0ef08e..ad943a06a6e21 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -2015,7 +2015,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; diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js index d0fd115fd15c6..e328e656edda4 100644 --- a/src/librustdoc/html/static/js/scrape-examples.js +++ b/src/librustdoc/html/static/js/scrape-examples.js @@ -57,7 +57,7 @@ }); }); - example.querySelector("next") + example.querySelector(".next") .addEventListener("click", () => { onChangeLoc(() => { locIndex = (locIndex + 1) % locs.length; diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 1f87f95563ad5..b48b82307ebc3 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -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"); From 5a9fffc593046abaa3522cfe0a1a59c7decdc61d Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Sat, 26 Nov 2022 23:27:10 -0600 Subject: [PATCH 2/3] Add test for scrape-examples next/prev buttons --- .../rustdoc-gui/scrape-examples-button-focus.goml | 15 ++++++++++++++- .../src/scrape_examples/examples/check.rs | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/scrape-examples-button-focus.goml b/src/test/rustdoc-gui/scrape-examples-button-focus.goml index 2a263a87a4756..1eb04eb92d128 100644 --- a/src/test/rustdoc-gui/scrape-examples-button-focus.goml +++ b/src/test/rustdoc-gui/scrape-examples-button-focus.goml @@ -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| @@ -11,4 +24,4 @@ assert-property-false: (".scraped-example-list > .scraped-example pre", { store-property: (fullOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight") assert-property: (".scraped-example-list > .scraped-example pre", { "scrollHeight": |fullOffsetHeight| -}) +}) \ No newline at end of file diff --git a/src/test/rustdoc-gui/src/scrape_examples/examples/check.rs b/src/test/rustdoc-gui/src/scrape_examples/examples/check.rs index 3e69c6086ae2e..b3f682fe4973c 100644 --- a/src/test/rustdoc-gui/src/scrape_examples/examples/check.rs +++ b/src/test/rustdoc-gui/src/scrape_examples/examples/check.rs @@ -22,4 +22,5 @@ fn main() { println!("hello world!"); println!("hello world!"); } + scrape_examples::test(); } From f7a705929aa3f40ff5c3b1e569858a7030b2e3bd Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Mon, 5 Dec 2022 14:04:57 -0800 Subject: [PATCH 3/3] Restore missing newline --- src/test/rustdoc-gui/scrape-examples-button-focus.goml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/scrape-examples-button-focus.goml b/src/test/rustdoc-gui/scrape-examples-button-focus.goml index 1eb04eb92d128..a222139f1dc44 100644 --- a/src/test/rustdoc-gui/scrape-examples-button-focus.goml +++ b/src/test/rustdoc-gui/scrape-examples-button-focus.goml @@ -24,4 +24,4 @@ assert-property-false: (".scraped-example-list > .scraped-example pre", { store-property: (fullOffsetHeight, ".scraped-example-list > .scraped-example pre", "offsetHeight") assert-property: (".scraped-example-list > .scraped-example pre", { "scrollHeight": |fullOffsetHeight| -}) \ No newline at end of file +})