feat(ui): copy button on code blocks (LC-272) #314
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/lc-272-code-copy-button"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Adds a "Copy" button to each rendered code block (LC-272). Hovering or focusing a fenced code block reveals a button in the top-right that copies the raw code to the clipboard and briefly flips to "Copied" - no more hand-selecting multi-line snippets that scroll horizontally.
How
layout.html) wraps each.lc-md prein a relative container and drops the button beside it (a sibling of the<pre>, not inside it, so the copied text is never polluted by the button's own label). It readspre.textContent, which copies cleanly even for syntect-highlighted blocks (those carry styled spans and no inner<code>).navigator.clipboard.writeTextwith the__lcCopyFallbacklegacyexecCommandfallback.htmx:afterSettle/htmx:oobAfterSwap, idempotent via adata-lc-code-donemarker, so live-arriving and edited messages (and other markdown surfaces) get a button too.main.css:.lc-code-wrap/.lc-code-copy(absolute top-right, revealed on hover/focus). Strings localized in en + es.Progressive enhancement: with JS off the code still renders and is selectable. Pure front-end - no markdown/template render change, so no LC-77 fixture impact. No route/DB/env. Not operator-visible.
Tests
routes_drafts::page_ships_code_copy_enhancerasserts the page ships the enhancer + idempotency marker.just testandjust test-saaspass.Note
Caught one self-inflicted regression during the run: a code comment in the enhancer contained the literal string
hx-swap-oob, which (sinceadmin_layout.htmlextendslayout.html) landed in the admin page body and trippedroutes_quotas'!body.contains("hx-swap-oob")assertion. Reworded the comment; all green.QA note
JS-driven, so worth a quick manual pass: post a fenced code block, hover it (Copy button appears top-right), click (copies the exact code, flips to "Copied"); confirm a highlighted block (e.g. ```rust) copies without color artifacts; confirm a code block in a live-arriving message and in a room wiki/description also gets the button; tab to the button to confirm it is focusable.