Skip to content

fix(mobile): wrap code blocks and keep long ones expandable - #713

Merged
huichen merged 2 commits into
mainfrom
fix/mobile-code-wrap
Sep 17, 2026
Merged

huichen merged 2 commits into
mainfrom
fix/mobile-code-wrap

Conversation

@huichen

@huichen huichen commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

A fenced code block in a mobile chat message was rendered as a horizontal scroll region; past 10 000 characters or 16 lines it also became a fixed 360 dp inner FlatList. Two consequences, both visible in the report:

  • Nothing wrapped. A CJK paragraph inside a fence could only be read by panning sideways, so most of the block was off-screen.
  • The tail was unreachable. The 360 dp inner viewport clipped the block mid-line, and its vertical pan is lost to the surrounding message list — the bottom of the block simply was not there, with no affordance saying so.

Change

mobile/src/components/MarkdownText.tsx (CodeSource):

  • Code now renders at the block width — the horizontal ScrollView is gone, so Text wraps naturally (the columns/fontScale width computation and codeContent style go with it).
  • A long block (same large threshold as before) collapses to a wrapped 16-visual-line preview with a tail ellipsis, plus an explicit 展开代码 / 收起代码 control. Expanding paints every bounded source chunk inline, so the whole block is reachable by scrolling the message — no nested vertical viewport, no lost gesture.
  • 16 keeps the old fixed viewport's worth of text (360 dp held ~17 unwrapped lines) while never clipping a line; because large implies more than 16 visual lines, the control is never a no-op.
  • Copy still copies the unmodified source, and collapsed previews still mount only one bounded chunk (the height bound is new; the character bound is unchanged).

mobile/docs/remaining-performance-2026-09-16.md and the paired docs/internals/mobile/markdown-rendering-audit{,.zh-CN}.md acceptance item were updated — "horizontally readable to the end" is no longer the expected behaviour.

Verification

  • mobile: npx jest src/components src/i18n --runInBand (266 tests, incl. rewrapped code tests), tsc --noEmit, eslint --max-warnings 0; related suites (TimelineCard, MarkdownImage, fileActionSurfaces, markdownParsing, codePreviewRows, codeHighlight) all pass.
  • Rendered through the real mobile UI in the screenshot harness (demo data) and measured in the DOM: collapsed preview is -webkit-line-clamp: 16 / line-height: 20px → 344 px tall with scrollHeight 492 (truncated, ellipsis); after expanding, clientHeight === scrollHeight (504) with the previously hidden tail lines painted; the control toggles both ways and is a 350×44 target.

Not verified: a real-device touch pass on Android/iOS (the checklist item above covers it).

A fenced block was a horizontal scroll region, and past 10k characters or 16
lines it became a fixed 360dp inner FlatList. On a phone that meant prose in a
fence could not be read at phone width, and the tail of a long block sat behind
a nested vertical viewport that loses the pan gesture to the message list.

Render code at the block width instead (no horizontal ScrollView), and collapse
a long block to a wrapped 16-line preview with a tail ellipsis plus an explicit
expand/collapse control that paints every bounded chunk inline — the tail is one
tap away rather than unreachable. Copy still yields the unmodified source.
@huichen
huichen enabled auto-merge (squash) September 17, 2026 14:39
@huichen
huichen merged commit 07a6bde into main Sep 17, 2026
12 checks passed
@huichen
huichen deleted the fix/mobile-code-wrap branch September 17, 2026 14:42
huichen added a commit that referenced this pull request Sep 26, 2026
A table with more than 20 rows kept the rest behind a fixed 360dp inner list.
That viewport did not scroll on the phone: the vertical drag belongs to the
list the table sits in, which takes the move before the nested list sees it, so
the promise printed under the table ("scroll inside the table to see the rest")
was false and rows 21+ could not be reached at all — the same nested-viewport
failure the long code block was fixed for in #713.

Paint the first 20 rows and put the rest behind an explicit control, which
paints every remaining row inline and lets the surrounding list scroll them.
The horizontal scroller stays: a wide table still pans sideways.
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