Skip to content

feat(ui): add copy button to user message code blocks#20946

Open
sandikodev wants to merge 7 commits intoanomalyco:devfrom
sandikodev:feat/user-message-code-copy-button
Open

feat(ui): add copy button to user message code blocks#20946
sandikodev wants to merge 7 commits intoanomalyco:devfrom
sandikodev:feat/user-message-code-copy-button

Conversation

@sandikodev
Copy link
Copy Markdown

@sandikodev sandikodev commented Apr 3, 2026

Issue for this PR

Closes #20943

Type of change

  • New feature

What does this PR do?

While working on #20942, I noticed code blocks in user messages had no
copy button — unlike code blocks in AI responses. This adds one to the
top-right of the language label bar, using IconButton for consistency
with the rest of the UI.

This PR depends on #20942 and is submitted as draft until that one merges.

How did you verify your code works?

Tested manually — button appears on hover, copies to clipboard, shows
check icon briefly then resets.

Screenshots / recordings

1. Copy button visible (hover state)
image

2. Copied state
image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Parse backtick syntax in user message text before rendering.
Triple backticks render via Markdown component (with syntax highlight),
single backticks render as inline <code> elements.

Closes anomalyco#12791
- Replace Markdown component with native pre/code render to eliminate
  excess spacing from prose styles
- Auto-collapse code blocks exceeding 8 lines with show/hide toggle
- Add styling for inline code and code block in user-message-text
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
keys to en.ts and use them in CodeBlock component instead of
hardcoded strings.
Add ui.message.codeBlock.showMore and ui.message.codeBlock.showLess
to all 16 non-English locale files.
Reduce margins on headings, paragraphs, hr, pre, and table elements
to improve visual density in AI responses. Values were previously
too large (2rem/2.5rem) causing excessive whitespace around code
blocks and section dividers.
When a fenced code block is extracted from user message text, the
closing ``` leaves trailing newlines that become orphan whitespace
in the next text segment. These are artifacts of the markdown syntax,
not intentional user spacing, so they are trimmed.

This is open for discussion — an alternative is to preserve them
and let the container handle spacing via CSS.
Add a copy button to the header bar of code blocks in user messages,
consistent with the existing copy button in AI response code blocks.
Uses IconButton component for design system consistency.

Closes anomalyco#20943
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one directly related PR:

Related PR:

No duplicate PRs found with overlapping functionality. PR #20946 is complementary to #20942, building on its code block improvements by adding copy functionality.

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.

[FEATURE]: Add copy button to code blocks in user messages

1 participant