fix(direction): only honor inline w:bidiVisual for table visual direction (SD-3171)#3354
Merged
caio-pizzol merged 2 commits intoMay 17, 2026
Merged
Conversation
…tion (SD-3171) Word-parity bug exposed by SD-3138 Phase 1B. The Phase 1B cascade code layered style-resolved rightToLeft/bidiVisual into TableDirectionContext when no inline value was present. That matches how most cascading properties work, but Word's actual renderer behaves differently for w:bidiVisual specifically: it does not visually flip cells when the only source is a style. The flip only fires when w:bidiVisual is on the table inline. Empirical verification: - Style-cascade fixture (bidiVisual in w:style/w:tblPr only): Document.Tables(1).TableDirection = 1 (wdTableDirectionLtr), cells render A B C in logical order. - Inline fixture (bidiVisual in w:tbl/w:tblPr): TableDirection = 0 (wdTableDirectionRtl), cells render C B A flipped. Fix: drop the style fallback when computing tableDirectionContext. visualDirection. Style-cascade resolution stays for all other table properties (borders, cell margins, etc.); only the visual flip signal becomes inline-only. Explicit inline `false` continues to honor `??` semantics so an inline bidiVisual w:val="0" still produces 'ltr'. Tests: - pm-adapter table.test.ts: "style cascade rightToLeft=true" assertion flipped from 'rtl' to undefined (Word-parity contract). Inline-only tests and the explicit-false alias test still pass. - All 63 table.test.ts tests green; layout-bridge / painter-dom / contracts unchanged. Behavior tests updated in a follow-up commit so the rtl-style-derived- bidivisual.spec.ts assertion matches the corrected contract. Closes part of SD-3171.
…e cascade (SD-3171) Update the rtl-style-derived-bidivisual.spec.ts assertion from C B A to A B C - the Word-parity contract that the pm-adapter fix in the previous commit installs. The original assertion in PR #3350 pinned SuperDoc's pre-fix behavior, not Word's. Add rtl-inline-bidivisual.spec.ts as the positive control: a fixture where w:bidiVisual is set INLINE on the table's tblPr. Word's renderer visually flips cells here (TableDirection=wdTableDirectionRtl, cells render C B A). SuperDoc must match. Both fixtures load a 1x3 table with logical cells A B C. The pair proves the fix is direction-specific: - style-cascade source -> no visual flip (Word-parity, both render A B C) - inline source -> visual flip (Word-parity, both render C B A) Both specs pass on chromium, firefox, webkit. Inline fixture includes the default TableNormal style so the super- converter can anchor its style cascade; the bare custom style version without TableNormal triggered a docxImporter throw.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Word-parity bug exposed by SD-3138 Phase 1B (#3285). The Phase 1B cascade code layered style-resolved `rightToLeft`/`bidiVisual` into `TableDirectionContext` when no inline value was present. That matches how most cascading properties work, but Word's actual renderer behaves differently for `w:bidiVisual` specifically: it does NOT visually flip cells when the only source is a style. The flip only fires when `w:bidiVisual` is on the table inline.
Empirical verification
Document.Tables(1).TableDirectionw:tbl/w:tblPrFix
`packages/layout-engine/pm-adapter/src/converters/table.ts`: drop the style fallback when computing `tableDirectionContext.visualDirection`. Style-cascade resolution stays for all other table properties (borders, cell margins, etc.); only the visual cell-flip signal becomes inline-only. Explicit inline `false` continues to honor `??` semantics so `<w:bidiVisual w:val="0"/>` still produces `'ltr'`.
History
PR #3350 (Wave 3 coverage fixture) originally asserted the style-cascade fixture renders C B A — pinning SuperDoc's pre-fix behavior as a test. This PR updates that assertion to A B C (Word parity) and adds an inline-bidiVisual positive control (C B A) so a future regression on either path fails loudly.
Tests
Follow-up
Will upload both fixtures to the R2 corpus as broad layout-compare regression coverage after this lands.
Closes SD-3171.