Skip to content

feat(xref): copy a citation to the clipboard when its cell is clicked#529

Merged
marcoscaceres merged 2 commits into
mainfrom
feat/xref-click-to-copy
Jun 30, 2026
Merged

feat(xref): copy a citation to the clipboard when its cell is clicked#529
marcoscaceres merged 2 commits into
mainfrom
feat/xref-click-to-copy

Conversation

@marcoscaceres

@marcoscaceres marcoscaceres commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Render each citation as its own button so a click or Enter/Space copies just that citation to the clipboard, with a toast. Second of three PRs splitting #495; adds tests.

Landing order: land after #497 and rebase onto main; #497, #529, #511 all edit static/xref/script.js. Suggested batch order: #499, #500, #501, #497, #529, #511 (#424 independent).

@marcoscaceres
marcoscaceres requested a review from sidvishnoi June 24, 2026 13:51
Comment thread static/xref/script.js Outdated
<td>${entry.shortname}</td>
<td>${entry.type}</td>
<td>${cite}</td>
<td><button type="button" class="cite-cell" title="Copy citation">${cite}</button></td>

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.

a11y wise, I think the copy button should be dedicated copy button. Like:

<td>${cite} <button>Copy</button></td>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reworked this for a11y. Each citation is now its own real <button class="cite"> (the citation text is the button), so clicking/tapping the citation copies it and the <td> keeps its native cell role — no role="button" on the cell. Dropped the per-button title (it became a redundant description repeated on every button) in favour of aria-label="Copy citation …", and a role="status" toast confirms the copy.

Comment thread static/xref/script.js Outdated
Comment on lines +234 to +242
// Builds the citation text for the clipboard, turning the <br> separators
// between multiple `for` contexts into newlines so each citation is on its
// own line (textContent alone would concatenate them with no separator).
function citeTextFromCell(cell) {
return [...cell.childNodes]
.map(node => (node.nodeName === 'BR' ? '\n' : node.textContent))
.join('')
.trim();
}

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.

Should it copy one item only? I don't see the benefit of copying multiple options at once, given only one need to be used. Maybe it can copy the least/most specific one?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good call — it now copies one item only. Each for-context citation is rendered as its own button with its own click target, so clicking e.g. [=stack/item=] copies just that one citation rather than all the options joined together.

@marcoscaceres
marcoscaceres force-pushed the feat/xref-click-to-copy branch from 08ba987 to f6097b6 Compare June 30, 2026 03:51
Each citation in the How to Cite column is its own button; clicking or tapping it copies just that citation, with a toast confirmation. Citation buttons carry an aria-label (Copy citation …) for screen readers and keep the table cell's native role.
@marcoscaceres
marcoscaceres force-pushed the feat/xref-click-to-copy branch from f6097b6 to 9f12015 Compare June 30, 2026 04:56
Mirror clipboard.test.js: throw a clear error if the vm slice no longer captures the citation helpers (e.g. after a rename), instead of silently testing the wrong region.
@marcoscaceres
marcoscaceres requested a review from sidvishnoi June 30, 2026 08:45
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