[PR #11638] feat(tui): add rich text clipboard support for copying formatted content #13871

Open
opened 2026-02-16 18:18:42 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11638

State: open
Merged: No


Summary

  • Add markdownToHtml() converter with inline styles for cross-editor compatibility
  • Add copyRich() clipboard function supporting Linux (Wayland/X11), macOS, with graceful fallback
  • Add selection-to-markdown matching to find original markdown from rendered terminal text
  • Add copy_as_rich_text config option (defaults to false) and runtime toggle in command palette

Fixes #10693

Technical Details

Markdown to HTML Conversion

Uses the marked library with a custom renderer that applies inline styles to all elements. This ensures formatting is preserved when pasting into editors that strip external CSS (Google Docs, Notion).

Clipboard Platform Support

  • Linux Wayland: wl-copy --type text/html
  • Linux X11: xclip -selection clipboard -t text/html
  • macOS: AppleScript with hex-encoded HTML data
  • Windows/SSH/tmux: Plain text fallback (rich text not supported)

Selection Matching

When copying selected text, the system attempts to find the original markdown source using:

  1. Exact substring match
  2. Normalized whitespace/case comparison
  3. Stripped markdown syntax matching
  4. Partial match for selections covering >30% of content

Caveats

  • Rich text copy requires wl-copy (Wayland) or xclip (X11) to be installed on Linux
  • Remote sessions (SSH, tmux, screen) always fall back to plain text
  • Windows does not support rich text copy (falls back to plain text)
  • Selection matching may not find the source markdown for heavily transformed or partial selections

Test Plan

  • Unit tests for markdown-to-HTML conversion (31 tests)
  • Unit tests for clipboard operations (16 tests)
  • Manual test: Copy message with Ctrl+Y, paste into Google Docs
  • Manual test: Select text, Ctrl+C, paste into rich text editor
  • Manual test: Toggle setting via command palette (Ctrl+P)
  • Manual test: Verify plain text fallback in SSH session
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11638 **State:** open **Merged:** No --- ## Summary - Add `markdownToHtml()` converter with inline styles for cross-editor compatibility - Add `copyRich()` clipboard function supporting Linux (Wayland/X11), macOS, with graceful fallback - Add selection-to-markdown matching to find original markdown from rendered terminal text - Add `copy_as_rich_text` config option (defaults to false) and runtime toggle in command palette Fixes #10693 ## Technical Details ### Markdown to HTML Conversion Uses the `marked` library with a custom renderer that applies inline styles to all elements. This ensures formatting is preserved when pasting into editors that strip external CSS (Google Docs, Notion). ### Clipboard Platform Support - Linux Wayland: `wl-copy --type text/html` - Linux X11: `xclip -selection clipboard -t text/html` - macOS: AppleScript with hex-encoded HTML data - Windows/SSH/tmux: Plain text fallback (rich text not supported) ### Selection Matching When copying selected text, the system attempts to find the original markdown source using: 1. Exact substring match 2. Normalized whitespace/case comparison 3. Stripped markdown syntax matching 4. Partial match for selections covering >30% of content ## Caveats - Rich text copy requires `wl-copy` (Wayland) or `xclip` (X11) to be installed on Linux - Remote sessions (SSH, tmux, screen) always fall back to plain text - Windows does not support rich text copy (falls back to plain text) - Selection matching may not find the source markdown for heavily transformed or partial selections ## Test Plan - [x] Unit tests for markdown-to-HTML conversion (31 tests) - [x] Unit tests for clipboard operations (16 tests) - [x] Manual test: Copy message with Ctrl+Y, paste into Google Docs - [ ] Manual test: Select text, Ctrl+C, paste into rich text editor - [x] Manual test: Toggle setting via command palette (Ctrl+P) - [ ] Manual test: Verify plain text fallback in SSH session
yindo added the pull-request label 2026-02-16 18:18:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13871