Skip to content

feat(mobile): add code block rendering and copy button#803

Draft
wpfleger96 wants to merge 1 commit into
mainfrom
worktree-wpfleger+mobile-code-block-parity
Draft

feat(mobile): add code block rendering and copy button#803
wpfleger96 wants to merge 1 commit into
mainfrom
worktree-wpfleger+mobile-code-block-parity

Conversation

@wpfleger96
Copy link
Copy Markdown
Collaborator

Brings mobile code block support to parity with desktop (PR #788). Rendered messages now display fenced code blocks with custom styling — rounded border, muted background, GeistMono font, horizontal scroll, optional language label — and an always-visible copy-to-clipboard button, replacing gpt_markdown's default CodeField.

The composer already had the code block toolbar button from #788 but lacked auto-fence detection. Typing ``` (with optional language tag) followed by Enter now auto-expands into a full fenced block template with the cursor positioned inside, matching the desktop Tiptap InputRule behavior.

  • Add _MessageCodeBlock widget via gpt_markdown's codeBuilder callback, styled to match desktop's MarkdownCodeBlock (12px radius, outline border at 0.7 alpha, surfaceContainerHighest bg at 0.6 alpha)
  • Add _expandFenceIfNeeded helper that detects a completed ``` fence line on newline and expands it, with a fence-count guard to avoid triggering inside existing blocks
  • Add isModifyingText re-entrancy guard (useRef<bool>) to prevent infinite recursion between the controller listener, applyCodeBlock, and _expandFenceIfNeeded

…ence

Desktop's code block support (PR #788) landed with a toolbar button but
no equivalent rendering or composer UX on mobile. The sent messages used
gpt_markdown's default CodeField with hard-coded Material styling that
didn't match the design system.

Adds _MessageCodeBlock (via gpt_markdown's codeBuilder callback) with
rounded border, muted bg, GeistMono font, horizontal scroll, optional
language label, and an always-visible copy-to-clipboard button. Also adds
_expandFenceIfNeeded to auto-expand ```lang + Enter into a full fenced
block template in the composer. A useRef isModifyingText guard prevents
the controller listener from re-entering _expandFenceIfNeeded while
applyCodeBlock or the expander itself is mutating the controller, which
was causing a StackOverflow crash.
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.

1 participant