Skip to content

Commit 6047a03

Browse files
Add tooltip for important traits display
1 parent d86621f commit 6047a03

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/librustdoc/html/render.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,7 @@ fn render_spotlight_traits(item: &clean::Item) -> Result<String, fmt::Error> {
32553255

32563256
fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
32573257
let mut out = String::new();
3258+
let mut trait_ = String::new();
32583259

32593260
if let Some(did) = decl.output.def_id() {
32603261
let c = cache();
@@ -3265,9 +3266,10 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
32653266
.map_or(false, |t| t.is_spotlight) {
32663267
if out.is_empty() {
32673268
out.push_str(
3268-
&format!("<h3 class=\"important\">Important traits for {}</h3>",
3269+
&format!("<h3 class=\"important\">Important traits for {}</h3>\
3270+
<code class=\"content\">",
32693271
impl_.for_));
3270-
out.push_str("<code class=\"content\">");
3272+
trait_.push_str(&format!("{}", impl_.for_));
32713273
}
32723274

32733275
//use the "where" class here to make it small
@@ -3288,8 +3290,11 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
32883290
}
32893291

32903292
if !out.is_empty() {
3291-
out.insert_str(0, "<div class=\"important-traits\">ⓘ<div class=\"content hidden\">");
3292-
out.push_str("</code></span></div></div>");
3293+
out.insert_str(0, &format!("<div class=\"important-traits\"><div class='tooltip'>ⓘ\
3294+
<span class='tooltiptext'>Important traits for {}</span></div>\
3295+
<div class=\"content hidden\">",
3296+
trait_));
3297+
out.push_str("</code></div></div>");
32933298
}
32943299

32953300
Ok(out)

src/librustdoc/html/static/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@
17371737

17381738
onEach(document.getElementsByClassName('important-traits'), function(e) {
17391739
e.onclick = function() {
1740-
showModal(e.firstElementChild.innerHTML);
1740+
showModal(e.lastElementChild.innerHTML);
17411741
};
17421742
});
17431743

src/librustdoc/html/static/rustdoc.css

+1
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ pre.rust {
958958

959959
.important-traits {
960960
cursor: pointer;
961+
z-index: 2;
961962
}
962963

963964
h4 > .important-traits {

src/test/rustdoc/doc-spotlight.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<T: SomeTrait> SomeTrait for Wrapper<T> {}
1919
#[doc(spotlight)]
2020
pub trait SomeTrait {
2121
// @has doc_spotlight/trait.SomeTrait.html
22-
// @has - '//code[@class="spotlight"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
22+
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
2323
fn wrap_me(self) -> Wrapper<Self> where Self: Sized {
2424
Wrapper {
2525
inner: self,
@@ -32,15 +32,15 @@ impl SomeTrait for SomeStruct {}
3232

3333
impl SomeStruct {
3434
// @has doc_spotlight/struct.SomeStruct.html
35-
// @has - '//code[@class="spotlight"]' 'impl SomeTrait for SomeStruct'
36-
// @has - '//code[@class="spotlight"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
35+
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
36+
// @has - '//code[@class="content"]' 'impl<T: SomeTrait> SomeTrait for Wrapper<T>'
3737
pub fn new() -> SomeStruct {
3838
SomeStruct
3939
}
4040
}
4141

4242
// @has doc_spotlight/fn.bare_fn.html
43-
// @has - '//code[@class="spotlight"]' 'impl SomeTrait for SomeStruct'
43+
// @has - '//code[@class="content"]' 'impl SomeTrait for SomeStruct'
4444
pub fn bare_fn() -> SomeStruct {
4545
SomeStruct
4646
}

0 commit comments

Comments
 (0)