Skip to content

refactor: extract shared clipboard module from webidl-clipboard#5202

Merged
marcoscaceres merged 3 commits into
mainfrom
refactor/clipboard-shared
Apr 17, 2026
Merged

refactor: extract shared clipboard module from webidl-clipboard#5202
marcoscaceres merged 3 commits into
mainfrom
refactor/clipboard-shared

Conversation

@marcoscaceres

Copy link
Copy Markdown
Contributor

Summary

  • Extracts the copy button SVG and creation logic from webidl-clipboard.js into a shared clipboard.js module
  • webidl-clipboard.js now delegates to createCopyButton(".idlHeader")
  • Prepares for CDDL (feat(core/cddl): add CDDL support #5201) and other code block types to reuse the same copy functionality

Split out from #5201 per Sid's request.

Test plan

  • Modified Web platform tests — no observable behavior change (pure refactor)

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.

Pull request overview

This PR refactors the existing WebIDL copy-to-clipboard button implementation by extracting the shared copy button creation/copy logic into a reusable core/clipboard.js module, enabling reuse by other code block processors (e.g., upcoming CDDL support).

Changes:

  • Introduces src/core/clipboard.js with a shared createCopyButton(headerSelector) helper.
  • Updates src/core/webidl-clipboard.js to delegate to createCopyButton(".idlHeader").

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/core/webidl-clipboard.js Replaces inline copy-button creation/copy logic with a call to the shared helper.
src/core/clipboard.js Adds a shared copy-button factory and click handler that copies <pre> contents excluding a header element.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/clipboard.js Outdated
Comment thread src/core/clipboard.js Outdated
Comment thread src/core/webidl-clipboard.js Outdated
Move the copy button creation and SVG into a shared clipboard.js
module. webidl-clipboard.js now delegates to createCopyButton()
with ".idlHeader" as the header selector. This prepares for CDDL
and other code block types to reuse the same copy functionality.
@marcoscaceres marcoscaceres force-pushed the refactor/clipboard-shared branch from ac725c2 to 24f9760 Compare April 17, 2026 18:38

@sidvishnoi sidvishnoi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lgtm. Let's use copilot suggestion to add aria-label though. Rest is good.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Lgtm. Let's use copilot suggestion to add aria-label though. Rest is good.

Addressed in 2005e2a.

The shared copy button now sets aria-label from the configurable title value, and WebIDL uses "Copy IDL to clipboard" so tooltip and accessible name stay specific.

Screenshot: copy button title and aria-label

@marcoscaceres marcoscaceres merged commit 81a76f5 into main Apr 17, 2026
9 checks passed
@marcoscaceres marcoscaceres deleted the refactor/clipboard-shared branch April 17, 2026 19:46
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.

4 participants