openwork icon indicating copy to clipboard operation
openwork copied to clipboard

feat: add copy-to-clipboard functionality to markdown code blocks and…

Open rohitbathi opened this issue 4 months ago • 7 comments

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-4 when findOpen is 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 typecheck
  • pnpm --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

  1. Start the desktop client (pnpm dev).
  2. Open a session and ask the model for code (e.g. write a hello world in python).
  3. Click "Copy" on the new header bar, confirm the checkmark icon animates for 500ms, and verify clipboard contents.
  4. Scroll the chat page up/down to confirm the header stays stuck to the viewport header until the code block leaves the page.

Evidence

image

Risk

  • Low. Purely frontend layout and event interception changes.

Rollback

  • Revert commits to markdown.tsx and session-surface.tsx.

rohitbathi avatar Jul 05 '26 06:07 rohitbathi

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-landing Ready Ready Preview, Comment, Open in v0 Jul 7, 2026 6:54pm

vercel[bot] avatar Jul 05 '26 06:07 vercel[bot]

@rohitbathi is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 05 '26 06:07 vercel[bot]

The copy button itself works, but a few things below the line before this is ready.

  • [high] The change to session-surface.tsx removes the findOpen ? "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) code renderer 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 Shiki container, 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 hardcode stroke="#000000". In dark mode the header renders white and the icons black. Use theme tokens (e.g. bg-gray-1 / stroke-current or currentColor) so it follows the active theme — there is active theme work in flight here (#2447/#2466/#2329).
  • [minor] z-2 is not a default Tailwind utility; unless it is in your scale it is a no-op. Use z-[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.

rohitbathi avatar Jul 07 '26 04:07 rohitbathi

I've updated the PR to address the comments:

  • Replaced the hardcoded white/black styles with theme tokens (used bg-gray-1 and stroke="currentColor").
  • Resolved z-2 to z-[2].
  • Created a shared generateCodeBlockContainer helper 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 div dynamic 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

  1. App boots clean to a known route

image — 4 validations passed 2. **A new session is created and becomes active** - image — 3 validations passed 3. **The composer accepts a message and the agent responds** - ✅ Visible text does not include "Something went wrong" - image — 4 validations passed 4. **Reopening restores the session and its message history** - image — 4 validations passed

rohitbathi avatar Jul 07 '26 06:07 rohitbathi

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.

rohitbathi avatar Jul 07 '26 18:07 rohitbathi

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?

rohitbathi avatar Jul 17 '26 23:07 rohitbathi

Hey maintainers, is there anything else I need to do before the PR is accepted? Looking forward to your response

rohitbathi avatar Jul 31 '26 23:07 rohitbathi