#58969: Fix double-click copying "Copied!" notice text to clipboard in Privacy Policy Guide#12008
#58969: Fix double-click copying "Copied!" notice text to clipboard in Privacy Policy Guide#12008masteradhoc wants to merge 4 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
westonruter
left a comment
There was a problem hiding this comment.
This isn't working for me. When I double-click, I'm still seeing the “Copied!” text at the end:
...
Where your data is sent
Visitor comments may be checked through an automated spam detection service.
Copied!
It seems like the underling approach to copying and hiding the undesireable content is not ideal. Why not just wrap the text that actually should be copied in a DIV and target that for copying? Then we don't need to mess around with hiding other content temporarily.
|
Thank you very much for the review @westonruter, always appreciated. Tested locally and over https://playground.wordpress.net/?core-pr=12008 both work perfectly. |
The "Copy suggested policy text to clipboard" action selected the entire accordion panel, whose contents include the actions toolbar holding the "Copied!" confirmation notice and the button label. Running `document.execCommand( 'copy' )` copies every text node in the selection, including ones hidden with CSS. So double-clicking the button, which renders the notice, leaked "Copied!" into the clipboard. Wrap the suggested policy text in a dedicated `.privacy-text-copy-content` container and select only that node, so the actions toolbar is never part of the copied range. Developed in #12008. Follow-up to r47572, r50161. Props masteradhoc, vivekawsm, westonruter, sruthi89, sumitbagthariya16. Fixes #58969. git-svn-id: https://develop.svn.wordpress.org/trunk@62663 602fd350-edb4-49c9-b593-d223f7449a82
The "Copy suggested policy text to clipboard" action selected the entire accordion panel, whose contents include the actions toolbar holding the "Copied!" confirmation notice and the button label. Running `document.execCommand( 'copy' )` copies every text node in the selection, including ones hidden with CSS. So double-clicking the button, which renders the notice, leaked "Copied!" into the clipboard. Wrap the suggested policy text in a dedicated `.privacy-text-copy-content` container and select only that node, so the actions toolbar is never part of the copied range. Developed in WordPress/wordpress-develop#12008. Follow-up to r47572, r50161. Props masteradhoc, vivekawsm, westonruter, sruthi89, sumitbagthariya16. Fixes #58969. Built from https://develop.svn.wordpress.org/trunk@62663 git-svn-id: http://core.svn.wordpress.org/trunk@61948 1a063a9b-81f0-0310-95a4-ce76da25c4cd
When a user double-clicks the "Copy suggested policy text to clipboard" button, the "Copied!" notice text was included in the clipboard contents when pasted.
The root cause:
document.execCommand('copy')copies all text content within the selected range, including text that is merely visually hidden via CSS. The.success("Copied!") span and the button label both live inside.privacy-settings-accordion-actions, which sits inside the panel being selected — so their text was always part of the copy, becoming noticeable on double-click when the notice is visibly rendered.The fix adds
.privacy-settings-accordion-actionsto the existinghide-privacy-policy-tutorialclass beforeselectNodeContentsruns, then removes it immediately after — the same mechanism already used to exclude tutorial paragraphs from the copied content.Trac ticket: https://core.trac.wordpress.org/ticket/58969
Use of AI Tools
AI assistance: Yes
Tool(s): Claude (claude.ai)
Model(s): Claude Sonnet 4.6
Used for: Debugging and identifying the root cause; the fix was reviewed, tested, and approved by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.