feat(web): render fenced code as a container in the composer - #28
Open
BarretoDiego wants to merge 1 commit into
Open
feat(web): render fenced code as a container in the composer#28BarretoDiego wants to merge 1 commit into
BarretoDiego wants to merge 1 commit into
Conversation
Fenced code was painted per line, so a block read as ragged highlighted runs rather than one surface, and the fences sat in the way of the text. Promote a closed fence to a structural node. The block becomes one container the caret types inside, and the fences stop being rendered while remaining part of the prompt: the node synthesizes them in getTextContent(), the same collapsed-versus-expanded split the composer already uses for mention and skill chips. Inside a block the composer behaves like a code field. Typing ``` opens an empty block with the caret already inside, Enter breaks the line instead of sending, Tab indents and Shift+Tab outdents. Every one of those has a way back out — a second Enter on a blank last line, an arrow past either edge, or Backspace in an empty block — so the caret can never be trapped. Path and skill autocomplete stay quiet inside a block, where their triggers are literal text.
Thread transfer impact
This comment will update automatically after the next completed run. |
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.
Problem
Fenced code in the prompt composer was painted per line, so a block read as ragged highlighted runs rather than one surface, and the fence characters sat in the way of the text.
Fix
Promote a closed fence to a structural node (
ComposerCodeBlockNode). The block becomes one container the caret types inside, and the fences stop being rendered while remaining part of the prompt — the node synthesizes them ingetTextContent(), reusing the same collapsed-versus-expanded split the composer already has for mention and skill chips.Inside a block the composer behaves like a code field:
```opens an empty block with the caret already inside.@and$are literal.Every one of those has a way back out, so the caret can never be trapped: a second Enter on a blank last line, an arrow past either edge, or Backspace in an empty block.
A half-typed fence stays plain text and keeps the existing inline highlight — promoting it would move the caret out from under the user mid-keystroke. A pasted block is rebuilt from the prompt through the existing controlled update rather than by the typing path.
Notes
composerCodeBlocks.tsis the single place that decides where a block starts and ends, so the node, the segmentation, and the syntax scanner cannot drift apart.```\n```. That normalizes the one degenerate input where a block holding a single blank line is indistinguishable from an empty one; it collapses to empty rather than growing a line on every edit.Verification
40 new tests plus the 182 existing composer tests, targeted lint, and
tsgo --noEmitonapps/web— all green. The suites cover prompt round-tripping (text in → tree → identical text out), the collapsed/expanded cursor mapping across hidden fences, and fence detection.Two real bugs the tests caught while building: the block's opening boundary resolved outside the fence, so typing at the start of a block would have inserted before it; and the empty-block ambiguity above, which grew a line per edit.
Interactive behaviour is not verified. The tests prove the data layer only. Enter, Tab, the auto-close, the caret landing inside the container, and how the container actually looks were never exercised in a browser — that is what this PR needs a human pass for. No before/after images for the same reason.
Written by Claude Opus 5 in T3 Code.