Repository navigation
fix(markdown): wrap long lines in code blocks like pi's TUI - #1369
Merged
Merged
Conversation
Code fences rendered every line on one row (`white-space: pre` from the highlighter, `overflow-x: auto` on the streamed <pre>), so a long line, URL or path made the block scroll sideways, by thousands of pixels on a phone. pi's TUI wraps every rendered line, code blocks included. CodeBlock now renders each line as a flex row of its number and its text (`renderCodeLines()`, `.markdown-code-line`): the text wraps (`pre-wrap`, `overflow-wrap: anywhere` for tokens without spaces) and a wrapped line goes on under its text, never under the number. The text keeps the row's own classes, which color the later lines of a multi-line token such as a block comment. The streamed <pre> wraps the same way. No toggle: wrapping is the one behavior, as in the TUI. Copy still copies the source text. Each line is now exactly `lineHeight` tall (1px less than before, when the <pre>'s theme font and the code font mixed), as in the streamed <pre>, so a block no longer grows when its stream ends. Extension dialogs widen to show code that would scroll sideways (#947); with wrapping it never does, so the dialog fit now measures fences unwrapped for a moment and still grows where the screen allows, the code wrapping only past that. The code-block scroll-edge fade is dropped, since fences no longer scroll sideways. demo/ mirrors the change. Fixes #1360 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Long lines in code fences scrolled sideways, by over 2,000px on a phone, which makes model output in ``` blocks hard to read (#1360). The issue asked for a wrap toggle; instead fences now wrap by default, as pi's TUI does (it passes every rendered line, code blocks included, through
wrapTextWithAnsi). No toggle, no setting.Change
components/MermaidBlock.tsx:CodeBlockgives react-syntax-highlighter a small renderer (renderCodeLines()) that makes each line a flex row of its number and its text. The text wraps (pre-wrap,overflow-wrap: anywherefor URLs and paths with no space), and a wrapped line continues under its text, never under the number. The text span keeps the row's classes, so the middle lines of a block comment keep their color. The streamed<pre>wraps the same way. Copy still copies the source text.app/globals.css: the row rules (flex: 1 1 0, so layout does not first measure every line unwrapped); code fences leave the sideways scroll-edge fade.components/ChatWindow.tsx: extension dialogs widen for code that would scroll sideways ([Feature] 扩展弹窗尺寸可配置:长内容(如格式化 SQL)在 560px 宽弹窗里显示局促 #947, fix(chat): let extension dialogs and the custom panel be widened (#947) #1032). With wrapping it never does, so the fit measures fences unwrapped for a moment (.extension-dialog-measuring) and still grows where the screen allows; code wraps only past that.CodeBlockfollows (custom and compaction messages, skills and subagent viewers, the file viewer's Markdown preview, the Mermaid source view). The file viewer's source view and tool cards are unchanged.lineHeighttall (about 1px less than before, when the<pre>'s theme font and the code font mixed), the same as while streaming.e2e/extension-dialog.mjs,demo/mirror,docs/agents/sessions.md, tests incomponents/MermaidBlock.test.mjs.Verification
flex: 1 1 0: 75 fences / ~2,300 lines ≈ 220 ms vs 217 ms on main (4× CPU throttle).tsc --noEmit(root and demo), eslint,npm test2,872 tests, 0 fail; fulle2e/run.mjspasses except the minimap step that already fails on local macOS runs.Fixes #1360
🤖 Generated with Claude Code