Skip to content

Fix copy to clipboard is available only for rust snippets #447

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

Merged
merged 1 commit into from
Dec 13, 2017
Merged

Fix copy to clipboard is available only for rust snippets #447

merged 1 commit into from
Dec 13, 2017

Conversation

Listwon
Copy link
Contributor

@Listwon Listwon commented Sep 18, 2017

Fixes #432

@budziq
Copy link
Contributor

budziq commented Sep 18, 2017

Thanks for taking this up @Listwon 👍 !

There is just one caveat. The added clip button collides with already present buttons for rust code snippets.
untitled

Most likely the code for rust playpens and other code blocks could use unification/refactoring.

Copy link
Contributor

@budziq budziq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I am not sure if we don't want the clipboard support to be opt-in (the clipboard buttons look a little intrusive on pages with a lot of single line non rust code blocks like http://localhost:3000/cli/build.html) what do you think @azerupi?

@@ -234,7 +246,7 @@ $( document ).ready(function() {
var clipboardSnippets = new Clipboard('.clip-button', {
text: function(trigger) {
hideTooltip(trigger);
let playpen = $(trigger).parents(".playpen");
let playpen = $(trigger).parents("pre");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most likely we would no longer name this variable playpen


$("pre code").each(function(i, block){
var pre_block = $(this).parent();
if( !pre_block.hasClass('playpen') ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that we would prefer to have the button dock for each code/pre instead of specifically in the playgrounds. And only add additional buttons to (other than clipboard) to already existing button bar for rust specific snippets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait for your comments then.

@Listwon
Copy link
Contributor Author

Listwon commented Sep 18, 2017

@budziq yeah, my bad, it needs fixing and refactoring. I need to study the code more deeply :) Thanks for quick testing and feedback!

@Michael-F-Bryan
Copy link
Contributor

Hi @Listwon, did you ever get a chance to revisit this? It seems like a nice little feature to have. Especially for things like The Book, being able to copy an entire snippet at the click of a button would be quite convenient.

@Listwon
Copy link
Contributor Author

Listwon commented Nov 10, 2017

Hi @Michael-F-Bryan, sorry I didn't revisit it earlier. I've just updated book.js to the newest version and fixed the bug found by @budziq with duplicating copy buttons. @budziq please test this again, I don't see other bugs for now. If I'm not mistaken, adding opt-in requires changes in the Rust code in which I'm not fluent yet.

I'll try to find the time for some refactoring in this part, but for now it's working as I wanted ;)

@Michael-F-Bryan
Copy link
Contributor

If I'm not mistaken, adding opt-in requires changes in the Rust code in which I'm not fluent yet.

If you need anything from the Rust side of things, let me know. We just landed a PR (#457) which makes configuration a lot easier to work with, so that should greatly simplify the job of adding a new configuration item and making sure the renderer has access to it.

@donald-pinckney
Copy link
Contributor

I think this would also be a great feature to have, and in fact something I am writing right now would benefit from this. Are there any plans to get the ball rolling on this again, or is there anything I can do to help?

@Michael-F-Bryan
Copy link
Contributor

@donald-pinckney, it looks like most of the work for this feature is done and as far as I can tell everything looks okay.

I've got a couple spare hours, so I'm going to check out the changes locally and do a proper review now. If there aren't any issues then this PR will probably be good to merge.

@Michael-F-Bryan
Copy link
Contributor

From what I can tell this looks good to me. Copying works, it pops up a little "Copied!" tooltip, and the clipboard icon no longer collides with the other buttons.

@Michael-F-Bryan Michael-F-Bryan merged commit a280a30 into rust-lang:master Dec 13, 2017
@donald-pinckney
Copy link
Contributor

Awesome, thanks!

Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
Fix copy to clipboard is available only for rust snippets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants