Repository navigation
Render Markdown as it is typed in every composer - #1234
Conversation
leaf-text hosts CodeMirror 6 in a closed shadow root and answers the textarea members the runtime uses, so focus, drafts, Enter-to-send, carry and keyboard scopes keep working. Inline code, emphasis, strong, links and headings render as typed; their syntax hides unless the selection touches it. The value stays the exact Markdown source. Spike only: tests that drive the box with Locator.fill or textarea-only API still fail, and the bundle loads on the boot path. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Delegated focus handed the field to the first focusable node in its shadow tree, which is CodeMirror's scroller: c and any press in the box's padding showed the focus ring with no caret, and typing went nowhere. The element now defines focus the way a textarea does: focus() is CodeMirror's view.focus(), blur() leaves the words, and a press in the padding puts the caret at the nearest character. The placeholder is a layer under the words rather than a widget in the empty line, which the caret was drawn against. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
c from a thread in the panel went to the page's box: the thread's box was found with the selector 'textarea', which the switch to leaf-text left matching nothing. About a dozen modules each spelled text boxes out by tag, so the change broke lookups silently. focus.js now owns TEXT_FIELD, the tag of the box the runtime builds, and TEXT_BOX, every element that takes typed paragraphs, and every lookup reads one of them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every name for the runtime's text box now comes from focus.js. The widget API re-exports TEXT_FIELD and TEXT_BOX, so lf-options-addition offers TEXT_FIELD and lf-command's press filter reads TEXT_BOX. The render checks read TEXT_BOX, and so does the press list. CSS rules scoped to a runtime composer name leaf-text alone. Only the generic `.lf-ui` rules still name both tags, because lf-draft's plain-text editor is a native textarea. Comments and packages.md describe a text field. The field is now the control that tooling addresses. Its root is closed, so axe and Playwright see only the host. The host therefore takes role=textbox and aria-multiline, and carries the name, description and busy state. That clears axe's aria-prohibited-attr. The inner content node, where focus lands, wears the same aria-label and the placeholder. `placeholder` reflects its attribute, as a textarea's does. The root delegates focus, and CodeMirror's scroller gives up its tab stop. A focus that never meets the element's own focus() now lands in the words: the platform's, or Playwright's from its isolated world, where every fill, press and focus previously went to a host that takes no focus. The element's focus() writes the page selection from the field's own. CodeMirror's focus left a stale DOM range behind after a press elsewhere, then read the caret back as 0. A refocus now keeps the caret where it stood, as a textarea does. Tests: render_harness gains write(), which does for a field what `fill` does for a textarea. The chrome contracts now type through it, read values with to_have_js_property, and include leaf-text among the fields held to the entry font floor. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The field: - A write to `value` replaces the editor's state instead of dispatching an edit. Undo used to walk back past a draft the runtime loaded or a send's emptying, and it fired `input` doing so, which saved the result over the current draft. A new state is a new history, as a textarea's is, and every transaction left is the user's. - A paste that carries a picture is left to the box's owner. CodeMirror used to insert the clipboard's text first, or delete the selection when there was no text. - A link whose destination is on the next line keeps its syntax drawn. Hiding it replaced a line break, which CodeMirror refuses; the editor stayed dead after the throw. Brackets with no destination (`[1]`, `array[0]`) are no longer drawn as links, matching what marked sends. - The host is a tab stop (tabindex=0), as a textarea is. It used to read -1 while Tab stopped in it, so the Threads panel's Tab wrap and every stop-counting walk missed it. - The content node takes the host's description through ariaDescribedByElements, the one reference that crosses into the shadow root. - A field removed and not put back in the same task destroys its view, keeping the state for a later reconnect. - focus() writes the page selection only once the field actually holds focus. setSelectionRange clamps as a textarea's does. - The bundle drops `markdown()` and with it the HTML, CSS and JavaScript grammars: 489 KB becomes 299 KB (98 KB gzipped). Around it: the options row's ring keys on `:focus`, since Chrome never gives a delegating host `:focus-visible` and a focused text box is always visible focus. `surfaces.js` finds a page thread's own reply box through SAY_BOX rather than the first field in the thread. The dead `rows`, `autocomplete` and `field-sizing` for leaf-text are gone. The deploy verifier, the demo recorder and the MCP observer type into the field. Tests: every browser file now reaches the runtime's composers as `leaf-text`, types through write() and reads `value`. Behaviour that moved: - the ring checks accept `leaf-text:focus` for keyboard-visible focus, which tests/AGENTS.md now states; - the reactions test no longer asserts `autocomplete=off`, which a CodeMirror editor has no use for; - the visual review journey's anchor now carries the `identity` that #1184 added, and asserts the stable-identity quote stays current rather than "Earlier data". Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # tests/test_render_options_addition.py # tests/test_render_visual_review_journey.py
The composer changed materially, so the core gallery gains a focused specimen: which constructs style themselves as they are typed, that the syntax returns when the caret enters it, Shift+Enter, and that undo and the sent message hold exactly what was typed. The corpus is regenerated. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The send-key hint ("Reply" and its key badge) was an overlay beside the
box. It copied the box's padding and border, and it hid the box's own
placeholder with a transparent colour while it showed. The field now
draws both through one layer: a child in slot `placeholder` stands in
for the placeholder attribute, and wireInput slots its hint there while
there is a key to show. The layer is size-contained, as the overlay was,
so a placeholder never sizes its box. The overlay's grid placement,
padding copy, `lf-compose-hinted` switch and --lf-compose-border-width
are gone.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review of the fold found two regressions from its size containment: - In the response bar the layer was only one editor line tall, so it cut off the bottom of the key badge. - A placeholder longer than its field lost its second line with no mark that anything was missing. The layer now contains only its inline size, so no placeholder widens a response bar, and it clips only across. The plain placeholder and the keyed hint are each one line: the hint is 1lh tall with its badge painting into the padding, as the overlay's did, and a narrow field shortens the label with an ellipsis and keeps the key. A field reads the same height focused and unfocused. wireInput puts the hint in the field only while there is a key to show, rather than leaving an unslotted child whose style the page cannot read. The hint is unselectable apparatus. focus() now asks whether the content node holds focus rather than whether the window does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/assets/runtime/focus.js # tests/AGENTS.md
The Markdown specimen's paragraph takes Prettier's wrap, and the corpus follows. Main's merge had added the journey comment's `identity` a second time beside the sweep's own. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The link preview disagrees with the sent message in both directions. In the new decorator, only Link nodes get link styling; CodeMirror parses a plain https://example.com or email address as a URL node, while the message renderer turns either into a link. Conversely, [click](javascript:alert(1)) gets link styling here, but the message renderer removes the unsafe link. Since this editor promises to show how the sent message will read, the preview needs to follow the renderer's link recognition and URL policy.
The preview styled only `[words](url)` links, whatever the destination. The renderer makes links of bare addresses, emails and `<url>`, and it drops a destination its URL policy refuses (`javascript:`), leaving the words. The field now asks the renderer's own safeUrl, which markdown.js exports. A bare, email or angle-bracket address is drawn as a link when safe. A refused link hides its syntax and shows plain words. Image and definition destinations are no link. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The preview still decides link styling from CodeMirror's raw URL node, while the sent-message renderer decides from Marked's resolved destination. For [click](javascript:alert(1)), the raw text resolves as a relative HTTP URL here and receives link styling; Marked's inert <a> decodes the character reference to javascript:, so markdown.js removes the link. A reference link such as [ref][id] with [id]: https://example.com goes the other way: Marked renders a link, but this Link node has no URL child and the preview leaves it plain. Please resolve the same destination the message renderer uses, including references, before deciding which words look like links.
The preview read CodeMirror's raw URL text, which the renderer never sees: `javascript:` looked like a relative link here and is refused there, and `[words][id]` has no URL child at all. markdown.js now answers from source, through sourceLinks: pointy brackets dropped, backslash escapes and character references resolved by the same parser that decodes the rendered href, then the renderer's URL policy. The field resolves reference links (`[words][id]`, `[id][]`, `[id]`) through the draft's definitions, labels folded as CommonMark folds them, before asking. The browser framework's manifest records the new CodeMirror packages in the lock. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
sourceLinks still decides from a destination before Marked normalizes it. For [x](https://ex\ample.com), CodeMirror supplies a URL node and the preview styles x as a link: new URL treats the backslash as a separator. Marked encodes that backslash as %5C; the sent-message URL guard rejects the resulting host and renders plain x. I reproduced both outputs in Chromium. The composer and renderer need to judge the same normalized destination, so this new helper does not keep the link preview aligned with the sent message.
Reading a destination from source kept reproducing a piece of Marked: entities, then backslash escapes, and still not its normalization. A destination Marked encodes and then refuses (`https://ex\\ample.com`) was styled as a link. markdown.js now answers rendersLink(source) by rendering the source through the one renderer and asking whether a link survived. The field asks it of each link, with the definition a reference names. Until the lazily loaded parser has arrived, no link is drawn, and its arrival redraws every open field. sourceLinks is gone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
Bare local URLs still look like plain text in the composer even though the sent message links them. CodeMirror parses http://localhost as a plain paragraph with no URL node, so this path never calls rendersLink; Leaf's loaded renderer outputs <a href="http://localhost">http://localhost</a>. The preview's link candidates need to follow the renderer's recognition as well as its destination decision, or the two views still disagree on a common developer URL.
Each review round found another place where the preview and the sent message disagreed: a javascript: link, an encoded one, a reference link, a backslash Marked normalizes, then `http://localhost`, which CodeMirror's grammar does not see as a URL at all. Two Markdown parsers were deciding one thing. The preview now takes its constructs from Marked, the parser that renders the message. markdown.js exposes markdownTokens(source): the instance's lexer output, rendered once, so that the link hook has recorded on each link token whether it kept it. The field places each token in the draft by its exact `raw` source and styles it: - code, emphasis, strong and strikethrough, with their marks hidden until the selection touches them; - links the renderer kept; - headings, fenced code, quotes and list markers. A hidden range that would hold a line break stays drawn instead. Tokens are read when the words change and styled when the selection moves. Until the lazily loaded parser has arrived, the words stand plain. CodeMirror's Markdown grammar now serves only Shift+Enter's list continuation, and the bundle no longer exports syntaxTree. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
An escaped delimiter in a link label still breaks source placement. For [a\]b](https://example.com), Marked renders a link and records linked: true, but its child text token has raw: "a]b" while the source inside the label is a\]b. content() cannot find that child text in token.raw, so the composer gives the link no styling. The preview needs source coordinates that survive Marked's unescaping; searching the rendered child text inside the original source leaves this valid link looking plain.
Two gaps in placing the renderer's tokens: - A link label with an escaped bracket (`[a\\]b](url)`) went unstyled. The field found a construct's words by searching for its child tokens' text, and Marked's children hold unescaped text the source does not contain. - A table's cells were never visited, so strong words and links inside one stayed plain. Each inline construct's opening and closing syntax is now read from its own source: the delimiter run for code, emphasis, strong and strikethrough, and for a link the label's matching bracket, escapes skipped as CommonMark reads it. Table cells are visited in source order, header first. A backslash escape's backslash steps aside like other syntax, since the message sends the character alone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A container hands the renderer its content rewritten: a quote or list drops each continuation line's markers and indent, and a table cell drops an escaped pipe's backslash. A token read from that content has a `raw` the draft does not hold verbatim. So `| [a\\|b](url) |` and emphasis spanning two quoted lines went unstyled while the message rendered them. locate() finds such a token by walking exactly those two rewrites, and the field reads each construct's syntax and block shape from the text it located, not from the token's rewritten raw. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An exact match of a quoted paragraph's rewritten raw could land in a later unquoted block that happened to read the same, before the match that walks the quote's markers. The quote then lost its styling, and the later block was styled twice. locate() now takes the earliest run that maps, exact or through the rewrites, and place() bounds each child's search to the span of the token that holds it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… files (#1239) Leaf's checks should catch what breaks Leaf or visibly breaks a page, and that nothing else reports. This removes the ones that do neither, about 1,150 lines net. **Static (`version check`)** - Stray end tags and duplicate attributes. Chrome recovers both, and TurboHTML keeps the first duplicate value just as Chrome does. - The pinned-pixel-width column lint, and the `--lf-reading-column: 1` claim in the theme that existed only so the lint could find the column. The theme already caps `img, svg, video` at `max-width: 100%`, and `--render` measures overflow directly. The success line no longer names a column. - `language-*` class checks on a plain `<pre><code>`. Plain HTML claims no vocabulary, so the runtime now leaves a language outside `$languages` uncolored rather than throwing a console error. An `lf-code` `language` attribute is still held to the list. - Syntax checks of the vendored stylesheets on every check. `page init` checks them when it composes the layer. The page's own `<style>` and inline styles are still checked. **Browser (`--render`)** - `silentCuts` and `withheldRoom`. Both read Leaf's own runtime and theme; `readings.py`'s docstring already puts those checks in the suite rather than the per-page gate. - `unnamedFormFields`. Real Chrome raises that DevTools issue itself, and the gate already reads DevTools issues; the probe existed only so the suite's headless shell would see it. - The print pass: `paperWords`, `paperVoids`, and the print `coveredWords`. The stylesheet-link rule (`rel` and `href` only) stays: delivery and export read `attrs["href"]` directly. The syntax-contrast reading (`unreadSyntax`) also stays. Axe passes the code spans it catches, and page CSS can cause the failure. **Tests** - Deleted: tests that held only a cut reading. - Trimmed: the scrolling, room and edge-shade tests keep their layout assertions. - New: `test_a_plain_block_in_a_language_the_layer_cannot_color_stays_plain` fails against the old runtime, on the console error. `uv run pytest tests` passes (1438), and so does `npm run test:runtime`. #1234 edits `silentCuts`, which this deletes; whichever lands second resolves the conflict by taking the deletion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # skills/leaf/scripts/leaf/render-checks/layout.js
A composer now starts the shared Markdown import as it mounts, so the module had already loaded by the time the test tried to catch it at send. The test holds it from the first navigation instead; both state readings still wait on the one import it guards. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # tests/test_render_controls.py # tests/test_render_projection.py
A draft in the composer now reads in the faces of the message it will send. The Markdown preview (`composing/text-field.js`, #1234) took its constructs from the message renderer but wrote its own faces, which disagreed with the message from the start: | construct | draft before | sent message | |---|---|---| | inline code | 0.9em, 3px chip | 82%, 4px chip, 1px/5px padding | | strong, heading | weight 650 | 700 | | quote | upright, 3px `--border-2` rule, 8px inset | italic, 2px `--rule` rule, 10px inset in the panel | | link | underline in full accent | underline at 35% accent | | code block | `--code-bg` strip at 0.9em | framed `--pre-bg` block at `--code-size` | The theme's element rules stop at the field's closed shadow root, so the values they draw are now `:root` tokens in `theme.css` (`--code-inline-size/-pad/-r`, `--quote-rule/-style/-inset`, `--pre-inset`, `--link-underline`, `--link-underline-offset`). The `code`, `pre`, `blockquote` and `a` rules and the preview read the same tokens, and custom properties inherit into the shadow root. Strong, emphasis and strikethrough are drawn as `strong`, `em` and `del` elements, so the browser's default styles apply to them in the field as in the message; inline code is a `code` element. The preview draws a code block line by line, so its frame is each line's sides, closed on the first and last lines. The panel's narrower insets were `.lf-msg-body pre` and `.lf-msg-body blockquote` paddings in `chrome.css`. They are now the same tokens set on `.lf-thread-panel`, so a draft in the panel insets as the panel's messages do. This hunk sits at the message-body rules, away from the Threads-panel rules the unmerged Codex gallery tree edits. Page elements compute as before: on a served page, a quote, code block, inline code and link compute the values the old rules stated. The remaining difference is the container: the composer sets its words at 14px and a panel message at 13px, and a draft marks a heading by weight only. Before (current main), a sent message above the same Markdown drafted in the Threads panel's composer: <img alt="Before: the draft's quote is upright under a dark rule, its code block a tinted strip" src="https://raw.githubusercontent.com/max-sixty/leaf/3d5957c4643a250b49fd505b09e25032a6c149aa/pr-shots/md-faces-before.png" width="420"> After: <img alt="After: the draft's quote, code, link and code block match the sent message" src="https://raw.githubusercontent.com/max-sixty/leaf/3d5957c4643a250b49fd505b09e25032a6c149aa/pr-shots/md-faces-after.png" width="420"> Test: `test_a_draft_wears_the_faces_its_sent_message_wears` (`tests/test_chrome_contracts.py`) writes a Markdown comment to the log, opens it in the panel, drafts the same Markdown in the general composer, and compares each construct's computed face. It reads the draft through DevTools, which reaches the closed root. Setting the quote back to its old rule or inline code back to 0.9em fails it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Every text box the runtime builds for the user to write in is now
<leaf-text>: a CodeMirror 6 editor that shows the draft the way the sent message will read. That covers the Threads panel's general box, each thread's reply, the Comment composer, margin replies, widget thread outlets, and lf-options' "Another option" box.What the user sees
The styling comes from the renderer that sends the message rather than a second grammar.
markdown.jsmarkdownTokensreturns Marked's own tokens, rendered once, so the link hook has recorded whether it kept each link. The field places each token in the draft by its exact source. The preview and the message therefore agree on what is a link, including bare addresses,http://localhostand reference links, and a refusedjavascript:destination shows plain words; they agree likewise on what is code, emphasis or a heading. CodeMirror's own Markdown grammar serves only Shift+Enter's list continuation.The syntax that produces each style (backticks, asterisks, brackets,
#,>) is hidden until the selection touches it, so every character the user typed stays reachable. Nothing is converted: the value is always the exact source, which is what the agent reads and whatmarkedrenders once the message is sent. Shift+Enter continues a list or quote. Enter, Mod+Enter and Escape stay with Leaf's key dispatcher.lf-draftkeeps its native textarea. It edits plain text whose read view is not rendered, so Markdown styling there would misrepresent it.The element (
composing/text-field.js)focused(), the scope climb andcomposedPath()[0]all land on the host, as they do for a textarea. The host answers the textarea members the runtime uses:value, the selection triple,setSelectionRange,select,placeholder,readOnly,name. It firesinputfor user edits only.valuereplaces the editor's state, so undo never walks back into a draft the runtime swapped out.focus()restores the caret, as a textarea's does. The host is a tab stop.role=textbox, the name, the description and the busy state, which is what axe and Playwright can see. The focused content node carries the same name and placeholder, and takes the description throughariaDescribedByElements.wireInput, which uploads it.placeholderstands in for the attribute, which is howwireInputshows the send key as a key. This replaces the overlay that copied the box's padding and border. The placeholder is one line and ellipsizes, so a field reads the same height focused and unfocused.TEXT_FIELD(the tag) andTEXT_BOX(the field or any native textarea) are named once infocus.js. The widget API re-exports them for packages. Every lookup reads them, and so do the render checks and the CSS scoped to composers. Thec-to-thread regression during the spike was a selector still namingtextarea.Cost before presentation
vendor/codemirror.esm.jsis 299 KB minified (98 KB gzipped). It is built byscripts/vendor.py codemirrorfrom the editor core and the GFM language, withoutmarkdown()'s HTML, CSS and JS grammars. On alert-review, measured against main by the same probe, it andtext-field.jsadd two modules and 313 KB (+9%) to what the page loads by presentation. The median time to presentation stays within run-to-run noise: 391 and 420 ms on main, 400 and 455 ms on this branch.It loads with the boot graph because the composers are on screen at presentation: margin reply boxes, the open Threads panel's boxes, and a restored draft's box. They render the stored draft and take input from the first frame. Loading the editor after presentation would need a stand-in editor and a handover of value, selection and focus, which is left as a follow-up. Each composer also starts the shared Marked import as it mounts, so a page with no messages now fetches
marked.esm.js(46 KB, 14 KB gzipped) as well; that import stays off the presentation path.Tests
render_harness.write()types into a field the wayfilldoes for a textarea. Playwright'sfillrefuses a custom element.leaf-textand readsvaluewithto_have_js_property.leaf-text:focusas keyboard-visible focus, since Chrome never gives a delegating host:focus-visible(seetests/AGENTS.md);autocomplete=off.test_render_startup.pyholdsmarked.esm.jsfrom the first navigation, because the import now starts when a composer mounts rather than at the first send.🤖 Generated with Claude Code