Skip to content

feat: add a copy button to Markdown code blocks - #581

Merged
Tryanks merged 1 commit into
mainfrom
feat/code-block-copy
Oct 3, 2026
Merged

Tryanks merged 1 commit into
mainfrom
feat/code-block-copy

Conversation

@Tryanks

@Tryanks Tryanks commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Every fenced code block in Markdown gets a copy button in its top-right corner. It is the same ghost icon button the chat uses on messages, with the same two-second check mark. Right-click "Copy code" stays. Mermaid diagrams keep the right-click copy only.

 crates/ui/src/
 ├── chat/
-│   ├── components/assistant.rs   # owned copy_button + CopiedMark
-│   └── mod.rs                    # copied, _copied_task, mark_copied
+│   └── …                         # both now use widgets/copy.rs
 ├── markdown/
+│   ├── render.rs                 # button on the fence's first line only
+│   ├── state.rs                  # own CopiedMark + copy_code
+│   └── view.rs
 └── widgets/
+    └── copy.rs                   # action_button, copy_button, CopiedMark (moved here)
render_code_block(item)
  if item paints the fence's first line
    draw copy chip (muted background so code under it stays readable)
    on click → copy_code(whole fence, not the painted span)

A long block split across several root-list items shows exactly one button, and that button copies the whole fence, matching what the context menu copies.

Evidence

  • Before: no copy affordance on code blocks besides the context menu.
    After: gallery example in light and dark at 980 px shows the button in the block's corner.
  • Test: code_block_copy_button_copies_the_whole_fence drives the real root list, clicks the button of a 100-line fence that is split across items, and asserts the clipboard holds the whole fence without the trailing newline.
cargo fmt --all --check                                          ✓
cargo clippy -p tcode-ui --all-targets --locked -- -D warnings    ✓
cargo test -p tcode-ui --locked                                   286 passed

The click-to-check feedback in the live app was not exercised through the desktop automation harness (its synthetic clicks did not reach the unfocused GPUI window). The clipboard contract is covered by the test and the check icon reuses the chat's existing path.

Merge Danger

Door: two-way

UI only, no state or protocol change.

Blast Radius: layout

Code blocks gain a chip over the right end of their first line. The chip has a muted background so code under it stays readable, but a long first line in a narrow block now ends under it.

Every fenced code block gets the chat's copy button in its top-right corner,
once per fence even when a long block is split across root-list items. The
button and the two-second "copied" check it shows move out of the chat into
widgets::copy as copy_button and CopiedMark, which the chat and MarkdownState
now share, so one owner holds the feedback behaviour.
@Tryanks
Tryanks enabled auto-merge October 3, 2026 04:11
@Tryanks
Tryanks merged commit b535e02 into main Oct 3, 2026
7 checks passed
@Tryanks
Tryanks deleted the feat/code-block-copy branch October 3, 2026 04:18
@Tryanks Tryanks changed the title feat: copy button on Markdown code blocks feat: add a copy button to Markdown code blocks Oct 6, 2026
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.

1 participant