Skip to content

fix(mobile): paragraph direction comes from the enriched-markdown fork, not injected marks - #455

Merged
trancong12102 merged 1 commit into
mainfrom
onicode/mobile-rtl-native
Nov 19, 2026
Merged

trancong12102 merged 1 commit into
mainfrom
onicode/mobile-rtl-native

Conversation

@trancong12102

@trancong12102 trancong12102 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Mobile chose each paragraph's direction in JS by injecting RLM/LRM marks into the markdown (7bf1fd8). The marks broke autolinks next to them, cost a whole-document remark parse on every streamed update, and could not reach table cells. This moves the rule into the enriched-markdown fork, so iOS and Android decide direction natively.

What changed

  • The fork (1.2.0-oni.22, aislopware/enriched-markdown oni-v1.2.0-oni.22) adds writingDirection="word-majority". Each paragraph, list item, heading and table cell goes right to left when it has more right-to-left words than left-to-right ones. Like desktop's textDirection, it votes by sentence first, then by word, then takes the first word, and inline code doesn't count.
    • iOS applies it per paragraph through ParagraphStyleUtils, blockquotes and tables included.
    • Android (API 29+) uses a TextDirectionHeuristic. Measurement and drawing share it, and inline code and highlight backgrounds take their bidi offsets from the layout that draws the text. Text with no right-to-left character keeps the platform's fast first-strong path.
  • Onicode drops the JS marks. EnrichedMarkdownText defaults to word-majority. The pending question card keeps its whole-question direction on iOS. On Android it uses the native rule, because Android maps an explicit direction to first-strong.
Before After
iOS iOS before iOS after
Android Android before Android after

Before, the autolinks next to Arabic text lost their link styling, and "مرحبا then run the build and tests." was forced right to left. After, links work and the English sentence reads left to right.

Blockquotes and inline code, on iOS and Android:

iOS Android
iOS blockquotes and inline code Android blockquotes and inline code

Tests

  • Fork, Android: WordMajorityDirectionTest (6 tests, :react-native-enriched-markdown:testDebugUnitTest).
  • Fork, iOS: ENRMWritingDirectionTests. The example app's XCTest lane ran 97 tests, all passing.
  • Both native suites carry the single-paragraph cases from apps/web/src/textDirection.test.ts plus inline-code masking cases, so a mobile change that departs from desktop fails them.
  • markdownTextDirection.test.ts goes away with the JS marks.

Council review

Round 1: Codex (gpt-6.2-sol, high) and Claude Opus, on the first fork commit and the Onicode revert. Both confirmed the counting rule matches desktop's character for character, and that the revert is complete.

  • Both, iOS GitHub-flavor blockquotes never got word-majority: the quote view rendered and measured its children with first-strong. Fixed: the mode reaches quoted text, nested quotes and tables, in rendering and measurement.
  • Opus, inline code counted as words on mobile but not on desktop, so استخدم `npm run build` ثم `npm test` went LTR on phones. Fixed on both platforms: iOS masks the inline-code attribute, and Android resolves each paragraph that holds code ahead of time, with CodeSpan masked.
  • Codex, Android inline code and highlight backgrounds took bidi offsets from a separate first-strong layout. Fixed: they read the drawing layout.
  • Opus, a custom heuristic sent every English paragraph through full ICU bidi. Fixed: text with no right-to-left character uses FIRSTSTRONG_LTR.
  • Both, measurement fell back to LTR for neutral paragraphs where the views used the layout direction. Fixed: measurement uses the locale direction.
  • Both, the pending question card's explicit direction made Android fall back to first-strong. Fixed: Android keeps the word-majority default there.
  • Opus, copy desktop's cases into both native tests. Done.
  • Both, Android 7 to 9 keep first-strong, and the unit differs from desktop. Left, see below.

Round 2: both reviewers, on the fork's round-1 fixes. Opus confirmed all six fixed. Codex found no iOS issue. Neither found clipping, a thread-safety problem or a leak.

  • Both, the Android lookup is keyed by a paragraph's characters, so two paragraphs with the same characters but different inline code share one answer, and a plain paragraph can take a code paragraph's answer. Left: it needs identical paragraph text and is rare in agent output.
  • Codex and Opus, the selection path's bounding box paints over the text between non-adjacent pieces of a span that crosses a direction run, and a span ending exactly at a soft wrap can paint to the view edge. Left: this needs code or a highlight mixing directions, and the old geometry had the first flaw too.
  • Opus, rounded corners on inline code that wraps inside an RTL paragraph are on the wrong side. Left: visual only, and newly visible because the band itself is now in the right place.
  • Both, masking copies a paragraph once per code span on each streamed update. Left: linear, and cheaper than the per-span StaticLayout the old geometry built on every draw.
  • Opus, desktop's "Hebrew around a URL" and "English quoting one Hebrew word" cases are not copied, and static copies don't catch a desktop rule change. Left.

Each of these fork changes would mean another tarball and rebuilding both native clients, so they wait for the next fork release.

Left

  • Android 7 to 9 (API 24–28) keeps first-strong, because the heuristic hook needs API 29.
  • The unit differs from desktop. Desktop picks one direction per top-level block, so a whole list or quote goes one way. Mobile decides per paragraph, list item and cell.
  • Android lookup and background edge cases from round 2, above.
  • A hard line break splits a paragraph on Android but not on iOS, so Plantur␣␣\nهذا شرح عربي is LTR then RTL on Android, and RTL throughout on iOS and desktop.

Opus 5.5 in Claude Code, through Onicode.

🤖 Generated with Claude Code

…k, not injected marks

Mobile picked each paragraph's direction in JS by injecting RLM/LRM marks,
which broke autolinks next to them and re-parsed the whole document on every
streamed update. The enriched-markdown fork 1.2.0-oni.22 adds a native
word-majority writing direction on iOS and Android, matching desktop's
counting rule, so the marks go away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trancong12102
trancong12102 merged commit a560266 into main Nov 19, 2026
18 checks passed
@trancong12102
trancong12102 deleted the onicode/mobile-rtl-native branch November 19, 2026 21:26
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