feat: add copy-to-clipboard functionality to markdown code blocks and…
Add copy button to code blocks & remove conditional padding from session surface
Summary
- Added a functional copy button to Markdown code blocks.
- Enabled the code block header to stay sticky to the chat viewport during vertical scrolling.
- Removed the conditional top padding (
pt-16/pt-4whenfindOpenis active) from the chat session surface container.
Why
- Implements request #2478 to allow users to quickly copy code from the chat interface.
- Ensures the copy button stays visible while reading long blocks of code.
- Cleaned up conditional surface padding calculation in the session surface layout.
Issue
- Closes #2478
Scope
apps/app/src/components/markdown/markdown.tsx(HTML wrapper container structure, copy click listener, DOMPurify whitelisting)apps/app/src/react-app/domains/session/surface/session-surface.tsx(Session surface padding layout change)
Out of scope
- Customizing code syntax highlighting color schemes or individual token colors (controlled natively by the global Shiki theme settings).
Testing
Ran
pnpm typecheckpnpm --filter @openwork/app test
Result
- pass/fail:
pass - details: 117 pass 0 fail 229 expect() calls Ran 117 tests across 24 files. [458.00ms]
CI status
- pass:
pass - code-related failures: None
- external/env/auth blockers: None
Manual verification
- Start the desktop client (
pnpm dev). - Open a session and ask the model for code (e.g.
write a hello world in python). - Click "Copy" on the new header bar, confirm the checkmark icon animates for 500ms, and verify clipboard contents.
- Scroll the chat page up/down to confirm the header stays stuck to the viewport header until the code block leaves the page.
Evidence
Risk
- Low. Purely frontend layout and event interception changes.
Rollback
- Revert commits to
markdown.tsxandsession-surface.tsx.
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| openwork-landing | Preview, Comment, Open in v0 | Jul 7, 2026 6:54pm |
@rohitbathi is attempting to deploy a commit to the Different AI Team on Vercel.
A member of the Team first needs to authorize it.
The copy button itself works, but a few things below the line before this is ready.
- [high] The change to
session-surface.tsxremoves thefindOpen ? "pt-16" : "pt-4"top padding entirely. That padding is intentional — its own comment says it keeps the find bar from covering the first message on short transcripts that cannot scroll it clear. Dropping it reintroduces that bug, and it is unrelated to copy-to-clipboard, so it should come out of this PR.- [high] The base (non-highlighted)
coderenderer now returns a multi-line template with the<code>indented on its own line inside<pre>.<pre>preserves whitespace, so this injects a leading newline + indentation into every non-highlighted code block (visible during streaming before Shiki takes over). Also that renderer only gained a wrapper<div>— no copy button — while the button lives solely in the Shikicontainer, so the two code paths are inconsistent. Either keep<pre><code>on one line, or move the button into a shared wrapper both paths use.- [medium] The sticky header hardcodes
bg-white, and both SVGs hardcodestroke="#000000". In dark mode the header renders white and the icons black. Use theme tokens (e.g.bg-gray-1/stroke-currentorcurrentColor) so it follows the active theme — there is active theme work in flight here (#2447/#2466/#2329).- [minor]
z-2is not a default Tailwind utility; unless it is in your scale it is a no-op. Usez-[2](or a real scale value) so the sticky header layers as intended.- [nit] The clipboard failure path only does
console.log('Copy failed')— leftover log, and the user gets no feedback. Consider surfacing a brief failure state on the button (mirroring the success check-mark swap).
I am working on it, thanks for the feedback.
I've updated the PR to address the comments:
- Replaced the hardcoded white/black styles with theme tokens (used
bg-gray-1andstroke="currentColor"). - Resolved
z-2toz-[2]. - Created a shared
generateCodeBlockContainerhelper function so the copy button is consistent across both fallback and highlighted paths. - Added a visual red X-mark failure state on clipboard copy failure.
- Fixed the find-bar padding issue using a spacer
divdynamic height approach.
fraimz — ✅ PASSED
1 passed · 0 failed · 0 skipped — run 2026-07-07T06-56-01-979Z
Full frame proof with validated screenshots: evals/results/2026-07-07T06-56-01-979Z/fraimz.html (re-run: pnpm fraimz --flow core-flow)
✅ core-flow — Open app, send a message, get a response, reopen with session intact
-
App boots clean to a known route
Thanks for catching those! I've gone ahead and addressed both:
- Switched the sticky header background from bg-currentColor to bg-gray-1 (matching the container's surface color).
- Cleaned up the non-highlighted code path by stripping the duplicate border, background, padding, and rounding styles from the inner pre tag so the outer container owns it.
Let me know if everything looks good now, thanks again.
Thanks for the guidance. Is there anything I have skipped which I should've mentioned in my comment to make sure the pull request is accepted?
Hey maintainers, is there anything else I need to do before the PR is accepted? Looking forward to your response