This repository was archived by the owner on Feb 4, 2026. It is now read-only.
Update the copy-to-clipboard functionality in our code blocks#1825
Closed
low-perry wants to merge 1 commit intoslatedocs:devfrom
Closed
Update the copy-to-clipboard functionality in our code blocks#1825low-perry wants to merge 1 commit intoslatedocs:devfrom
low-perry wants to merge 1 commit intoslatedocs:devfrom
Conversation
realityking
suggested changes
Oct 15, 2025
realityking
left a comment
There was a problem hiding this comment.
IMHO a good change
Worth noting that this will break the copy functionality when used outside a secure context (without HTTPS).
| navigator.clipboard.writeText(text) | ||
| .then(() => { | ||
| // Add success feedback | ||
| const button = container.parentNode.querySelector('.copy-clipboard'); |
There was a problem hiding this comment.
You should be able to pass the button into copyToClipboard() from the event handler avoiding an extra lookup.
| .then(() => { | ||
| // Add success feedback | ||
| const button = container.parentNode.querySelector('.copy-clipboard'); | ||
| const originalHTML = button.innerHTML; |
There was a problem hiding this comment.
Instead of reading from the DOM this could be a variable also used in setupCodeCopy().
| }); | ||
| } | ||
|
|
||
| function setupCodeCopy() { |
There was a problem hiding this comment.
I'd suggest adding some feature detection code and checking for a secure context. If one of those conditions is not met, we shouldn't show the (then non-functional) copy button.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates the copy-to-clipboard functionality in our code blocks. The previous implementation used the now‑deprecated
document.execCommand('copy')per MDN guidance. To modernize our approach and ensure future compatibility, we've replaced the deprecated method with the new asynchronous Clipboard API. In addition, we've added immediate visual feedback to inform users when text has been successfully copied.Key Changes
The code now leverages
navigator.clipboard.writeText()to handle the copy operation, ensuring a more robust and future‑proof solution.On successful copying, the copy button temporarily changes its icon to indicate success (displaying a checkmark icon), then reverts back after 1 second. This provides clear, actionable feedback to users.
Code Changes
Before:
After:
Preview

This update not only aligns our implementation with modern web standards but also enhances the overall user experience with clear visual feedback. Let me know if there are any questions or further improvements you'd like to discuss!