Update the copy-to-clipboard functionality in our code blocks #1825
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!