feat(tui): add rich text clipboard support for copying formatted content#11638
Closed
rscarvalho wants to merge 3 commits intoanomalyco:devfrom
Closed
feat(tui): add rich text clipboard support for copying formatted content#11638rscarvalho wants to merge 3 commits intoanomalyco:devfrom
rscarvalho wants to merge 3 commits intoanomalyco:devfrom
Conversation
Add markdownToHtml() function that converts markdown to HTML with inline styles for compatibility with rich text editors like Google Docs, Notion, and LibreOffice. - Add marked dependency (^17.0.1) for markdown parsing - Implement custom renderer with inline styles for all elements - Support headers, lists, links, code blocks, tables, blockquotes - Proper HTML escaping to prevent XSS - Add copy_as_rich_text config setting (defaults to false) - Add comprehensive test coverage (31 tests, all passing)
Add copyRich() function to copy both plain text and HTML to the system clipboard with graceful fallback when rich text is not supported. 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/Other: Plain text fallback - SSH/Remote: Plain text fallback (OSC 52 doesn't support HTML) Features: - Add CopyRichResult discriminated union type - Add isRemoteSession() helper for SSH/tmux detection - Add commandExists() helper for tool availability checking - Never throws - always returns a result with descriptive reasons - Comprehensive test suite (16 tests covering all platforms and edge cases)
Add smart text selection matching to enable rich text copying when users select and copy text from assistant messages in the TUI. Features: - Add selection-to-markdown.ts with fuzzy matching to find original markdown from rendered text - Update all text selection handlers (app.tsx, dialog.tsx) to support rich text - Add runtime toggle command in command palette (Ctrl+P) - Add copyAsRichText signal to local context - Update copy handlers in session views to use markdown source Matching strategies: 1. Exact substring match 2. Normalized whitespace/case comparison 3. Stripped markdown syntax matching 4. Partial match for selections covering >30% of content When copy_as_rich_text is enabled and text is selected: - Attempts to find original markdown source - Converts to HTML and copies as rich text - Falls back to plain text if no match found - Shows appropriate toast messages (success/warning/error) This completes the rich text clipboard feature, allowing users to copy both via commands and text selection with formatting preserved in rich text editors.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
markdownToHtml()converter with inline styles for cross-editor compatibilitycopyRich()clipboard function supporting Linux (Wayland/X11), macOS, with graceful fallbackcopy_as_rich_textconfig option (defaults to false) and runtime toggle in command paletteFixes #10693
Technical Details
Markdown to HTML Conversion
Uses the
markedlibrary 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
wl-copy --type text/htmlxclip -selection clipboard -t text/htmlSelection Matching
When copying selected text, the system attempts to find the original markdown source using:
Caveats
wl-copy(Wayland) orxclip(X11) to be installed on LinuxTest Plan