rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.79k stars 12.5k forks source link

rustdoc: copy code button obscures scraped example expand button #129763

Closed willcrichton closed 1 week ago

willcrichton commented 2 weeks ago

Rustdoc's copy code button introduced in 9946a68 conflicts with the UI for interacting with scraped code examples. I noticed this in the wild in Bevy's documentation: https://docs.rs/bevy/0.14.1/bevy/app/struct.App.html#scraped-examples-1

In the upper right corner is a button for expanding a snipper:

Screenshot 2024-08-29 at 2 46 10 PM

But hovering over the snippet shows the copy code button, obscuring the expand button:

Screenshot 2024-08-29 at 2 46 24 PM

cc @GuillaumeGomez

GuillaumeGomez commented 2 weeks ago

Arf indeed. I think code unification will be needed for this feature with the other code blocks to prevent such regressions in the future. Gonna send a fix.

GuillaumeGomez commented 2 weeks ago

I decided to integrate the buttons with the existing code examples. For now it looks like this:

image

willcrichton commented 2 weeks ago

That looks great! Do the buttons have the same behavior where they only appear when you hover over the snippet?

GuillaumeGomez commented 2 weeks ago

Yes! I'm also planning to only generate them if they don't already exist on hover like the copy button (it is only created after you first hovered the code example), it'll reduce the HTML size quite a lot. I also simplified the HTML a bit (again, smaller). I almost didn't change anything in the scraped example JS code, which is quite nice. I expected more changes to be needed. Well done!