Skip to content

feat(core/clipboard): keep copy buttons in saved documents and confirm a copy - #5529

Open
marcoscaceres wants to merge 10 commits into
speced:mainfrom
marcoscaceres:feat/clipboard-copy-ack
Open

marcoscaceres wants to merge 10 commits into
speced:mainfrom
marcoscaceres:feat/clipboard-copy-ack

Conversation

@marcoscaceres

@marcoscaceres marcoscaceres commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3766 (Keep WebIDL copy button in exported documents), which I closed as by design. This reverses that: copy buttons on WebIDL and CDDL blocks now stay in saved documents. A copy that works shows a check and a "Copied!" bubble that fades out after 1.2 seconds, and screen readers announce "Copied!" too. A copy the clipboard refuses shows a "Could not copy!" bubble and is announced the same way, where it used to be an unhandled promise rejection. A click now copies once instead of twice. Pages served over plain http have no clipboard, so the button hides there. Claude wrote the change. Gemini wrote some of its tests and reviewed the rest.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Saved pages can retain stale confirmation state or hide available copy controls, overlapping timers can erase announcements, and buttons remain visible but nonfunctional without the runtime.

4 open issues
What changed in this PR

This PR extends ReSpec’s WebIDL and CDDL copy controls to saved specifications, reversing the export behavior discussed in #3766.

Changes:

  • Preserve copy buttons with exportable styles and a single delegated click handler.
  • Add localized visual and screen-reader confirmations, handle rejected writes, and hide buttons when the clipboard API is unavailable.
  • Add integration coverage for live and exported documents, feedback timers, accessibility, and export cleanup.
File Description
tests/​spec/​core/​clipboard-spec.js Adds clipboard behavior and export integration tests.
src/​styles/​webidl.css.js Removes the print rule relocated to clipboard styles.
src/​styles/​ui.css.js Moves copy-button styling out of the transient UI stylesheet.
src/​styles/​clipboard.css.js Adds persistent button, confirmation, accessibility, and print styles.
src/​core/​clipboard.js Preserves exported controls and adds delegated copying, localized feedback, and state cleanup.

Review effort: Balanced

Comment thread src/core/clipboard.js Resolved
Comment thread src/core/clipboard.js Resolved
Comment thread src/core/clipboard.js Resolved
Comment thread src/styles/clipboard.css.js Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Clipboard feedback can be overwritten by stale writes, clicks can be blocked by stopped propagation, messages can appear off-screen, and active feedback can appear in print.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Handle delegated clicks during capture

src/​core/​clipboard.js:192

This listener only sees clicks that bubble all the way to document. If an author places an IDL or CDDL block inside an interactive container that calls stopPropagation(), the copy button no longer works; the previous listener on the button did. Register the delegated listener in the capture phase so it also handles those clicks.

Medium severity Hide the entire copy button when printing

src/​styles/​clipboard.css.js:100

visibility: hidden on the button does not hide descendants that explicitly set visibility: visible. Printing while a confirmation is active can therefore print the check icon or the “Copied!”/failure bubble over the specification. Remove the entire button from print layout instead; the override must beat the more specific ready rule.

3 resolved since last review

Review effort: Balanced

Comment thread src/core/clipboard.js Resolved
Comment thread src/styles/clipboard.css.js Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved clipboard issues can leave buttons unusable in saved pages or documents with a form named “respec,” and can display stale or misleading confirmations.

No open issues 🎉

4 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid treating a named form as a ReSpec instance

src/​core/​clipboard.js:111

A document containing <form name="respec"> exposes that form as document.respec through HTML's named-property lookup. In the exported document this condition then skips the runtime, leaving every copy button hidden even though ReSpec is not running. Check for the actual ReSpec instance rather than just a truthy property.

Medium severity Repeat stale confirmation cleanup after DOMContentLoaded

src/​core/​clipboard.js:158

The saved runtime can execute before every copy button has been parsed. An IDL block moved after the script by src/core/render-biblio.js can then retain a saved confirmation indefinitely when the page is reopened. Repeat this cleanup after DOMContentLoaded, while preserving copies started by the new runtime.

Medium severity Hide copy buttons unless runtime initialization succeeds

src/​core/​clipboard.js:205

A browser-saved snapshot retains respec-copy-ready in its markup. If scripts are disabled or blocked by a content security policy, the copy buttons remain visible without a listener, and any saved confirmation can stay visible too. Gate visibility on non-serialized runtime state and add a scripts-blocked browser-snapshot test.

Medium severity Keep failure label visible during fade-out

src/​core/​clipboard.js:246

When a copy fails, removing data-failed immediately switches the bubble's content back to data-copied-label, while the CSS keeps the bubble visible for its 0.4-second fade-out. Readers therefore briefly see “Copied!” after “Could not copy!”. Keep the failure label selected until the fade completes, independently of the attribute that starts the transition.

3 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Browsers with clipboard support but without constructable or adopted stylesheets can throw before the saved runtime script is appended, blocking processing.

1 open issue

Review effort: Balanced

Comment thread src/core/clipboard.js Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fallback serializes its visibility rule into snapshots, leaving a nonfunctional copy button visible when scripts or the clipboard API are unavailable.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/core/clipboard.js Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate potential authored-content conflicts and localization and accessibility issues across document layouts.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The confirmation bubble can extend off-screen when a code block is near the viewport edge because its placement depends only on viewport width.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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