Skip to content

Commit 4fac361

Browse files
Fix z-indexes of code example feature and cleanup its CSS
1 parent 607878d commit 4fac361

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
@@ -2028,45 +2028,36 @@ in storage.js
20282028
padding-bottom: 0;
20292029
}
20302030

2031-
.scraped-example .code-wrapper .prev {
2031+
.scraped-example .code-wrapper .next,
2032+
.scraped-example .code-wrapper .prev,
2033+
.scraped-example .code-wrapper .expand {
20322034
position: absolute;
20332035
top: 0.25em;
2034-
right: 2.25em;
2035-
z-index: 100;
2036+
z-index: 1;
20362037
cursor: pointer;
20372038
}
2038-
2039+
.scraped-example .code-wrapper .prev {
2040+
right: 2.25em;
2041+
}
20392042
.scraped-example .code-wrapper .next {
2040-
position: absolute;
2041-
top: 0.25em;
20422043
right: 1.25em;
2043-
z-index: 100;
2044-
cursor: pointer;
20452044
}
2046-
20472045
.scraped-example .code-wrapper .expand {
2048-
position: absolute;
2049-
top: 0.25em;
20502046
right: 0.25em;
2051-
z-index: 100;
2052-
cursor: pointer;
20532047
}
20542048

2055-
.scraped-example:not(.expanded) .code-wrapper:before {
2049+
.scraped-example:not(.expanded) .code-wrapper:before,
2050+
.scraped-example:not(.expanded) .code-wrapper:after {
20562051
content: " ";
20572052
width: 100%;
20582053
height: 5px;
20592054
position: absolute;
2060-
z-index: 100;
2055+
z-index: 1;
2056+
}
2057+
.scraped-example:not(.expanded) .code-wrapper:before {
20612058
top: 0;
20622059
}
2063-
20642060
.scraped-example:not(.expanded) .code-wrapper:after {
2065-
content: " ";
2066-
width: 100%;
2067-
height: 5px;
2068-
position: absolute;
2069-
z-index: 100;
20702061
bottom: 0;
20712062
}
20722063

0 commit comments

Comments
 (0)