Skip to content

feat(web): highlight markdown syntax while typing in the composer - #26

Merged
BarretoDiego merged 1 commit into
mainfrom
feat/prompt-markdown-highlighting
Aug 25, 2026
Merged

BarretoDiego merged 1 commit into
mainfrom
feat/prompt-markdown-highlighting

Conversation

@BarretoDiego

Copy link
Copy Markdown
Owner

Problem

The prompt composer rendered every character the same, so a pasted code fence or an inline snippet was indistinguishable from prose until the message was sent.

Fix

Paint markdown syntax live using Lexical text formats on the composer's own text nodes rather than an overlay, so the highlight shares a layout pass with the existing mention/skill chips instead of competing with them for position. Node text is never rewritten — the submitted prompt stays byte-identical to what was typed (locked by a test).

Covers fenced blocks (including half-typed ones), inline code with N backticks, bold, italic, strikethrough, headings, quotes, lists, thematic breaks, and links/images. Delimiters are dimmed rather than hidden, so the text stays plain markdown.

  • composerMarkdownSyntax.ts — pure scanner, text in → styled ranges out. A highlighter, not a CommonMark parser: staying cheap and stable while a construct is half-typed beats matching every reference edge case.
  • composerMarkdownHighlight.ts — Lexical layer. Transforms on TextNode (typing) and ParagraphNode (structural rebuilds, chip insertion).

Notes:

  • Chips are opaque to the scanner, so a path like @src/_a_/b.ts cannot read as emphasis and offsets past a chip stay aligned.
  • Styles are interned and adjacent equal-style segments merged. Without this the transform splits a node, Lexical re-merges it, and the two loop forever — caught by the integration test before it could ship.
  • The scan is skipped past 20k characters so pasting a large diff stays cheap.
  • Inline code intentionally uses no border/padding/font-size change (unlike the rendered .chat-markdown variant) so the caret and line boxes never shift while typing.

Verification

vp test run on the two new suites (30 cases) plus the nine neighbouring composer suites (190 cases), targeted lint, and tsgo --noEmit on apps/web — all green.

Not visually verified in a real client. No before/after images: the change was never opened in a browser, so the paint is proven by unit and headless-Lexical tests only.

Written by Claude Opus 5 in T3 Code.

The prompt composer rendered every character the same, so a pasted code
fence or an inline `snippet` was indistinguishable from prose until the
message was sent.

Paint markdown syntax live using Lexical text formats on the composer's
own text nodes rather than an overlay, so the highlight shares a layout
pass with the existing mention and skill chips instead of competing with
them for position. Node text is never rewritten: the submitted prompt is
byte-identical to what was typed.

Covers fenced blocks (including half-typed ones), inline code, bold,
italic, strikethrough, headings, quotes, lists, thematic breaks, and
links. Delimiters are dimmed rather than hidden. Chips are opaque to the
scanner so a path like @src/_a_/b.ts cannot read as emphasis, and the
scan is skipped past 20k characters to keep large pastes cheap.
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL labels Aug 25, 2026
@BarretoDiego
BarretoDiego merged commit f4329cb into main Aug 25, 2026
6 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant