Skip to content

Add copy to clipboard for code snippets #1548

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add copy to clipboard for code snippets #1548

wants to merge 2 commits into from

Conversation

paoloredis
Copy link
Collaborator

@paoloredis paoloredis commented May 12, 2025

@andy-stark-redis
Copy link
Contributor

@paoloredis Great idea! Just some things for discussion...

The copy button appears to copy the whole example file each time. To me, it seems more natural that it should just copy the text of the snippet whose button you click. Ideally, if you have the eye icon enabled to show the whole file, the button should then copy the whole file at once. Also, I think it would be great to extend this feature to the command page snippets, but it's probably even more important there to copy just the isolated snippet text.

Just my thoughts - I'd love to hear what you and everyone else thinks about this. Basically a very good feature, though, even as it is.

@paoloredis
Copy link
Collaborator Author

To me, it seems more natural that it should just copy the text of the snippet whose button you click.

What do you mean with this? If we take the first snippet in this page https://redis.io/docs/staging/DOC-5217/operate/rc/api/examples/manage-subscriptions/, what should be copied in your opinion, just the POST "https://[host]/v1/fixed/subscriptions" line?

@andy-stark-redis
Copy link
Contributor

What do you mean with this? If we take the first snippet in this page https://redis.io/docs/staging/DOC-5217/operate/rc/api/examples/manage-subscriptions/, what should be copied in your opinion, just the POST "https://[host]/v1/fixed/subscriptions" line?

Sorry for the misunderstanding - TBH, it didn't occur to me that the copy button would appear on all code snippets (I assumed it was just the tabbed-code examples).

What I meant was that for the TCEs specifically, it copies the whole of the source file that backs the snippets for the page (eg, for hashes, if you click the copy button on the example at the top, it also copies all the other examples to the clipboard as well). Seems more natural for these if the button just copies the single snippet, if possible.

@paoloredis
Copy link
Collaborator Author

I didn't realize the tabbed code examples already had the copy button. So we need to decide whether we keep what we already have there or replace the copy button with the new one (and a new eye button)

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.

2 participants