Skip to content

[codex] Avoid intrinsic sizing for RTL markdown documents#72

Draft
omers-oai wants to merge 9 commits intomainfrom
codex/rtl-document-measured-width
Draft

[codex] Avoid intrinsic sizing for RTL markdown documents#72
omers-oai wants to merge 9 commits intomainfrom
codex/rtl-document-measured-width

Conversation

@omers-oai
Copy link
Copy Markdown

@omers-oai omers-oai commented Apr 9, 2026

Let's back of the idea to use intrinsic width since it caused issues with SubcomposeLayouts, instead to avoid over expanding stuff we make sure to add maxWidth only when the current layout direction and the needed one for compatibility are not the same.

Also refactored the code a bit so it's maybe cleaner, it's still a mess since interventions are needed all over the place

Codex:

Summary:

  • Removes the document-level RTL compatibility sizing wrapper.
  • Renders markdown once in BasicMarkdown, with no IntrinsicSize.Max, no document-level SubcomposeLayout, and no top-level forced max width.
  • Keeps RTL compatibility block-level: paragraphs/headings use first-strong text direction, and only fill parent width when their detected direction differs from the current layout direction.
  • Applies the same conditional RTL width helper to code block expansion points.
  • Uses the same opposite-direction width predicate for quote/list measurement, so same-direction content can stay compact while opposite-direction content still gets a full-width line box.
  • Keeps quotes/lists/code choosing their internal side when compatibility is enabled.
  • Passes the smaller enableRtlCompatibility boolean into width helpers instead of threading the full render options object.
  • Keeps markdown RTL helpers in richtext-markdown/.../rtl/RtlCompatibility.kt and UI RTL helpers in richtext-ui/.../rtl/RtlCompatibility.kt.
  • Keeps HTML block rendering direct only in compatibility mode so explicit centered HTML can keep its own alignment.
  • Enables RTL compatibility in the current RTL preview samples so before/after screenshots exercise the compatibility path.

Root cause:

  • The table crash came from asking the whole markdown document tree for intrinsic width. Markdown tables render through SubcomposeLayout, which cannot answer intrinsic measurement.
  • A document-level wrapper also made this path more complicated than needed. The simpler generic fix is to not wrap the document for RTL sizing at all; table/custom nodes now use normal measurement only.

Why the fill is conditional:

  • Same-direction text already starts on the correct side under the parent layout direction, so forcing fillMaxWidth() just expands compact previews.
  • Opposite-direction text still needs a parent-width line box so it can anchor to the far edge.
  • Outer alignment alone only moves the child rectangle; it does not change text direction, quote gutter side, or list marker side inside that child.

Testing:

  • git diff --check
  • ./gradlew :richtext-markdown:allTests
  • ./gradlew :android-sample:testDebugUnitTest :android-sample:recordRoborazziDebug
  • ./gradlew check

Artifacts:

  • Local HTML explanation with diagrams generated under ~/Downloads/codex-artifacts; screenshots were not uploaded to the PR.

omers-oai and others added 2 commits April 10, 2026 08:28
Co-authored-by: Codex <noreply@openai.com>
Enable the RTL compatibility samples to exercise compatibility mode, keep HTML block alignment explicit in compatibility mode, and avoid forcing paragraph alignment unless a containing block needs a shared side.

Co-authored-by: Codex <noreply@openai.com>
@omers-oai omers-oai force-pushed the codex/rtl-document-measured-width branch from 8d43aeb to 65687e6 Compare April 10, 2026 12:38
@omers-oai omers-oai changed the base branch from codex/rtl-table-preview-only to main April 10, 2026 12:39
omers-oai and others added 7 commits April 10, 2026 08:52
Skip the compatibility measurement slot when the parent already supplies a bounded max width, and keep the non-intrinsic measurement fallback only for unbounded layouts.

Co-authored-by: Codex <noreply@openai.com>
Render markdown once in compatibility mode and leave direction handling to the existing block-level paragraph, quote, list, and code paths. This removes both intrinsic sizing and the document-level max-width wrapper.

Co-authored-by: Codex <noreply@openai.com>
Codex: Avoid expanding same-direction markdown text while still giving opposite-direction paragraphs a parent-width line box for far-edge placement.

Co-authored-by: Codex <noreply@openai.com>
Codex: Applies the RTL compatibility width helper to paragraph, list, quote, and code block width expansion points while keeping the helper internal to each module boundary.

Co-authored-by: Codex <noreply@openai.com>
Codex: Pass the RTL compatibility flag directly to width helpers and keep UI RTL conversion helpers grouped in the UI RTL file.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
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