Extract the clipboard write shared by the copy features - #3306
Closed
enf0rc3 wants to merge 1 commit into
Closed
Conversation
copy-markdown.js carries a secure-context check plus an execCommand fallback for browsers where navigator.clipboard is unavailable. The heading copy button needs the same logic, so it moves to its own module rather than becoming a second copy. Behavior is unchanged: the same two code paths in the same order, with the warning prefix generalized from [copy-md] to [clipboard]. code-blocks.js still has its own simpler inline version. It is bound up in a larger icon-swapping flow, so it is left alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Pull request environment is available at https://stoctodocspr3306.z22.web.core.windows.net. You can view the ephemeral environment status in Octopus Deploy. This environment will be automatically deprovisioned when the pull request is closed, or after 7 days of inactivity. |
Contributor
Author
|
Superseded by #3303. navigator.clipboard.writeText has been Baseline since 2020, so the shared module and its execCommand fallback are unnecessary - the four-line write is inlined at the call site instead. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pure extraction, split out of #3303 so the heading work reviews on its own.
copy-markdown.jscarries a clipboard write with two code paths:navigator.clipboard.writeTextwhere a secure context allows it, falling back to a hidden textarea plusdocument.execCommand('copy')for HTTP and older browsers. The heading copy button in #3303 needs exactly the same logic, so it moves tosrc/scripts/modules/clipboard.jsrather than becoming a second copy.What changed
writeToClipboardandexecCommandCopyFallbackmove out of theCopyMarkdownclass into a module, unchanged apart from the warning prefix ([copy-md]→[clipboard]) and JSDoc types.copy-markdown.jsimports it and callswriteToClipboard(text)in place ofthis.writeToClipboard(text).No behavior change: the same two paths are tried in the same order, and the return contract (
trueon success) is the same.code-blocks.jshas its own simpler inline version. It is bound up in a larger icon-swapping flow, so it is left alone — worth a follow-up if this module proves out.Verification
pnpm buildexits 0, 2697 pages, on this branch alone.[clipboard]appears indist/docs/_astro/Default.astro_astro_type_script_index_0_lang.*.js), so the import resolves rather than being tree-shaken away.prettier --checkandcspellon both files: clean.Stacked on #3301.
🤖 Generated with Claude Code