Skip to content

Commit 6e20768

Browse files
authored
Rollup merge of rust-lang#103722 - GuillaumeGomez:cleanup-code-example-css, r=notriddle
Fix z-indexes of code example feature and cleanup its CSS When reviewing rust-lang#103650, I realized that the `z-index`es of this feature were completely broken: ![Screenshot from 2022-10-28 10-55-27](https://user-images.githubusercontent.com/3050060/198826360-0c5cbe5a-ea8e-452a-9504-38d3da3615e6.png) This PR fixes it by reducing the value of value under the one used for `.popover` (it could be completely removed but then it wouldn't be displayed as nicely). There was also a lot of duplicated CSS so I merged the rules. r? `@notriddle`
2 parents e4821d7 + 4fac361 commit 6e20768

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

src/librustdoc/html/highlight.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ pub(crate) fn render_source_with_highlighting(
7272
line_numbers: Buffer,
7373
href_context: HrefContext<'_, '_, '_>,
7474
decoration_info: DecorationInfo,
75+
extra: Option<&str>,
7576
) {
7677
write_header(out, "", Some(line_numbers), Tooltip::None);
78+
if let Some(extra) = extra {
79+
out.push_str(extra);
80+
}
7781
write_code(out, src, Some(href_context), Some(decoration_info));
7882
write_footer(out, None);
7983
}

src/librustdoc/html/render/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2869,10 +2869,6 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
28692869
write!(w, r#"<span class="prev">&pr;</span> <span class="next">&sc;</span>"#);
28702870
}
28712871

2872-
if needs_expansion {
2873-
write!(w, r#"<span class="expand">&varr;</span>"#);
2874-
}
2875-
28762872
// Look for the example file in the source map if it exists, otherwise return a dummy span
28772873
let file_span = (|| {
28782874
let source_map = tcx.sess.source_map();
@@ -2906,7 +2902,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
29062902
cx,
29072903
&root_path,
29082904
highlight::DecorationInfo(decoration_info),
2909-
sources::SourceContext::Embedded { offset: line_min },
2905+
sources::SourceContext::Embedded { offset: line_min, needs_expansion },
29102906
);
29112907
write!(w, "</div></div>");
29122908

src/librustdoc/html/sources.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ where
258258

259259
pub(crate) enum SourceContext {
260260
Standalone,
261-
Embedded { offset: usize },
261+
Embedded { offset: usize, needs_expansion: bool },
262262
}
263263

264264
/// Wrapper struct to render the source code of a file. This will do things like
@@ -274,14 +274,18 @@ pub(crate) fn print_src(
274274
) {
275275
let lines = s.lines().count();
276276
let mut line_numbers = Buffer::empty_from(buf);
277+
let extra;
277278
line_numbers.write_str("<pre class=\"src-line-numbers\">");
278279
match source_context {
279280
SourceContext::Standalone => {
281+
extra = None;
280282
for line in 1..=lines {
281283
writeln!(line_numbers, "<span id=\"{0}\">{0}</span>", line)
282284
}
283285
}
284-
SourceContext::Embedded { offset } => {
286+
SourceContext::Embedded { offset, needs_expansion } => {
287+
extra =
288+
if needs_expansion { Some(r#"<span class="expand">&varr;</span>"#) } else { None };
285289
for line in 1..=lines {
286290
writeln!(line_numbers, "<span>{0}</span>", line + offset)
287291
}
@@ -297,5 +301,6 @@ pub(crate) fn print_src(
297301
line_numbers,
298302
highlight::HrefContext { context, file_span, root_path, current_href },
299303
decoration_info,
304+
extra,
300305
);
301306
}

src/librustdoc/html/static/css/rustdoc.css

+12-21
Original file line numberDiff line numberDiff line change
@@ -2023,45 +2023,36 @@ in storage.js
20232023
padding-bottom: 0;
20242024
}
20252025

2026-
.scraped-example .code-wrapper .prev {
2026+
.scraped-example .code-wrapper .next,
2027+
.scraped-example .code-wrapper .prev,
2028+
.scraped-example .code-wrapper .expand {
20272029
position: absolute;
20282030
top: 0.25em;
2029-
right: 2.25em;
2030-
z-index: 100;
2031+
z-index: 1;
20312032
cursor: pointer;
20322033
}
2033-
2034+
.scraped-example .code-wrapper .prev {
2035+
right: 2.25em;
2036+
}
20342037
.scraped-example .code-wrapper .next {
2035-
position: absolute;
2036-
top: 0.25em;
20372038
right: 1.25em;
2038-
z-index: 100;
2039-
cursor: pointer;
20402039
}
2041-
20422040
.scraped-example .code-wrapper .expand {
2043-
position: absolute;
2044-
top: 0.25em;
20452041
right: 0.25em;
2046-
z-index: 100;
2047-
cursor: pointer;
20482042
}
20492043

2050-
.scraped-example:not(.expanded) .code-wrapper:before {
2044+
.scraped-example:not(.expanded) .code-wrapper:before,
2045+
.scraped-example:not(.expanded) .code-wrapper:after {
20512046
content: " ";
20522047
width: 100%;
20532048
height: 5px;
20542049
position: absolute;
2055-
z-index: 100;
2050+
z-index: 1;
2051+
}
2052+
.scraped-example:not(.expanded) .code-wrapper:before {
20562053
top: 0;
20572054
}
2058-
20592055
.scraped-example:not(.expanded) .code-wrapper:after {
2060-
content: " ";
2061-
width: 100%;
2062-
height: 5px;
2063-
position: absolute;
2064-
z-index: 100;
20652056
bottom: 0;
20662057
}
20672058

0 commit comments

Comments
 (0)