Skip to content

fix(direction): auto-detect paragraph base direction via dir="auto"#3714

Open
shri-scale wants to merge 2 commits into
superdoc-dev:mainfrom
shri-scale:fix/rtl-auto-paragraph-direction
Open

fix(direction): auto-detect paragraph base direction via dir="auto"#3714
shri-scale wants to merge 2 commits into
superdoc-dev:mainfrom
shri-scale:fix/rtl-auto-paragraph-direction

Conversation

@shri-scale

Copy link
Copy Markdown
Contributor

auto-detect paragraph base direction via dir="auto"

Problem

Paragraphs with no explicit w:bidi render without a dir attribute. An absent dir makes the element inherit its container's base direction rather than auto-detecting from content — so a new/empty paragraph cannot pick up direction from the first strong character typed (e.g. typing Arabic on a fresh line stays LTR), and an editor embedded in an RTL/LTR shell takes the wrong base direction.

Change

  • Render dir="auto" for direction-unset paragraphs in both the editing node view (ParagraphNodeView) and the viewing painter (inline-direction/rtl-styles), so the browser resolves base direction per UAX minimal core infra for existing functionality #9 from the first strong character.
  • Explicit rightToLeft true/false remain hard overrides → dir="rtl" / dir="ltr".
  • setParagraphDirection({ direction: "ltr" }) now writes an explicit false (previously it deleted the flag) so a deliberate LTR choice survives auto-detection; reverting to auto stays clearParagraphDirection().
  • Updates the direction README to reflect the absent-dir vs dir="auto" distinction.

Tests

  • Unit: ParagraphNodeView, painter rtl-styles, paragraphDirection.
  • Behaviour: tests/behavior/tests/formatting/auto-paragraph-direction.spec.ts — auto-detect RTL/LTR on typing, and manual override persistence.

Note for reviewers

This changes the rendered dir for previously-undirected paragraphs (absent → auto), so visual snapshots may shift for documents containing such paragraphs. Those diffs should be reviewed and re-blessed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c010389625

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@shri-scale

Copy link
Copy Markdown
Contributor Author

@caio-pizzol kindly review

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@shri-scale shri-scale force-pushed the fix/rtl-auto-paragraph-direction branch from c010389 to 3c99448 Compare June 11, 2026 18:54
Paragraphs with no explicit w:bidi previously rendered without a `dir`
attribute, which inherits the container base direction instead of
auto-detecting from content. A fresh paragraph therefore could not pick up
direction from the first strong character typed (Google-Docs behaviour).

Render `dir="auto"` for unset paragraphs in both the editing node view
(ParagraphNodeView) and the viewing painter (inline-direction/rtl-styles), so
the browser resolves base direction per UAX superdoc-dev#9. Explicit `rightToLeft`
true/false remain hard overrides (`dir="rtl"`/`"ltr"`). `setParagraphDirection`
LTR now writes an explicit `false` so a deliberate LTR choice survives
auto-detection (reverting to auto is `clearParagraphDirection`).

This aligns the implementation with the direction README's stated intent;
README updated. Adds unit coverage (ParagraphNodeView, rtl-styles,
paragraphDirection) and a behaviour spec.
… line

The painter splits a paragraph into separate `.superdoc-line` elements and
stamped `dir="auto"` on each, so every wrapped line re-detected direction from
its own first strong character (an RTL paragraph whose continuation line begins
with Latin text wrongly flipped to LTR).

Resolve the base direction once on the paragraph wrapper (`dir="auto"`); lines
now inherit it via a new `inheritAuto` flag on `applyRtlStyles` (they leave
`dir` unset in the auto case, keep explicit rtl/ltr). The container render path
(table cells / text boxes) lacks a per-paragraph wrapper, so each paragraph's
lines are grouped under a `display:contents` wrapper that carries the direction
without affecting flex layout.
@shri-scale shri-scale force-pushed the fix/rtl-auto-paragraph-direction branch from 3c99448 to accd6ce Compare June 12, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants