Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy code to clipboard button in rustdoc #119979

Closed
wants to merge 0 commits into from
Closed

Add copy code to clipboard button in rustdoc #119979

wants to merge 0 commits into from

Conversation

grey4owl
Copy link

@grey4owl grey4owl commented Jan 14, 2024

A very simple button that was missing in the upper right corner to copy the code blocks to the clipboard. It is hidden by default, but when you hover over the code block (<pre>) element then it appears.. It also works on mobile devices and it will appears after you tap on the code block.

It looks like this:
Screenshot from 2024-01-13 17-11-48
Screenshot from 2024-01-13 17-12-02

r? @fmease

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jsha (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 14, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

@rustbot rustbot assigned fmease and unassigned jsha Jan 14, 2024
@rust-log-analyzer

This comment has been minimized.

@fmease fmease added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Jan 14, 2024
@fmease
Copy link
Member

fmease commented Jan 17, 2024

Before I can do a full review, could you please make CI pass (run ./x.py fmt again to make ./x.py test tidy pass) and address the ESLint errors:

EsLint errors
  1739:9   error  'preElements' is never reassigned. Use 'const' instead                   prefer-const
  1740:9   error  'filterElements' is never reassigned. Use 'const' instead                prefer-const
  1741:28  error  Unexpected function expression                                           prefer-arrow-callback
  1741:42  error  'index' is defined but never used. Allowed unused args must match /^_/u  no-unused-vars
  1743:13  error  'copyBtn' is never reassigned. Use 'const' instead                       prefer-const
  1744:13  error  'icon' is never reassigned. Use 'const' instead                          prefer-const
  1745:43  error  Unexpected function expression                                           prefer-arrow-callback
  1746:17  error  'code' is never reassigned. Use 'const' instead                          prefer-const
  1747:17  error  'summary' is never reassigned. Use 'const' instead                       prefer-const
  1752:57  error  Unexpected function expression                                           prefer-arrow-callback
  1757:43  error  Unexpected function expression                                           prefer-arrow-callback

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2024

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member

fmease commented Feb 6, 2024

@grey4owl Any updates on this? If you need any assistance with the CI failures, you can contact me on https://rust-lang.zulipchat.com/ for specific questions.

@grey4owl
Copy link
Author

grey4owl commented Feb 6, 2024

@fmease Sorry i just doesn't have so much free time right now.. I made a new commit, maybe it will go through CI now 🥲

@GuillaumeGomez
Copy link
Member

We still need to debate over this UI change: is it worth if there is code below it? Shouldn't we instead add a "space" at the top of the code block to put extra buttons there? For example, a while ago it was proposed to add an "expand" button to show the hidden lines (here). In addition, we could also move the "run" button into this "space".

Overall, having overlaying buttons isn't great I think.

@rust-log-analyzer

This comment has been minimized.

@grey4owl
Copy link
Author

grey4owl commented Feb 6, 2024

@GuillaumeGomez I don't know, it's useful for me when I want to quickly copy the multi-line code (crate example) rather than manually selecting everything and maybe left out some lines. In terms of how the button is displayed, rust book and crates.io uses this hover effect approach as well. And I think it will be more useful here than it is used on the crates.io where you need to copy just one short line of code which you can easily remember..

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member

Didn't say it was not useful, I'd like for rustdoc to have this feature. I'm saying that the hover approach is likely not the right one.

@rustbot rustbot added A-meta Area: Issues & PRs about the rust-lang/rust repository itself WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 6, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2024

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@fmease fmease added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues & PRs about the rust-lang/rust repository itself needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants