SD-2447 - fix: tab stop computation and alignment for TOC styles#2731
SD-2447 - fix: tab stop computation and alignment for TOC styles#2731chittolinag wants to merge 13 commits intomainfrom
Conversation
…sed-list-of-tablesfigures-toc
…sed-list-of-tablesfigures-toc
…-tablesfigures-toc' into gabriel/sd-2447-bug-toc-renders-with-incorrect-formatting-after-document
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3d1bb3dc3
ℹ️ 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".
| indentLeft: number, | ||
| rawFirstLineOffset: number, | ||
| ): void => { | ||
| const totalTabRuns = runs.reduce((count, run) => (run.kind === 'tab' ? count + 1 : count), 0); |
There was a problem hiding this comment.
Count inline tab characters when mapping alignment stops
applyTabLayoutToLines() now maps the last tab ordinals to explicit end/center/decimal stops, but totalTabRuns only counts runs with kind === 'tab'. In paragraphs where a tab remains embedded in a text run (the TOC/PAGEREF case this commit targets), consumeTabOrdinal() still advances for "\t" characters, so later ordinals are treated as out-of-range and the explicit right-aligned stop is applied to the wrong tab (or not applied at all). This leaves remeasurement output inconsistent with the DOM measurer and keeps TOC page-number alignment incorrect for mixed tab-run/text-tab input.
Useful? React with 👍 / 👎.
Co-authored-by: Caio Pizzol <97641911+caio-pizzol@users.noreply.github.com>
…-tablesfigures-toc' into gabriel/sd-2447-bug-toc-renders-with-incorrect-formatting-after-document
Issue
computeTabStops()stopped seeding the default 0.5″ grid whenever any explicit tab existed, so TOC paragraphs (which only declare a right-aligned dot-leader tab) lost their left-aligned defaults and the first\tjumped straight to the leader. Even after the grid was restored, the DOM measurer and layout remeasurement consumed the first explicit stop for every tab, so the final TOC tab often targeted a default stop instead of the right-aligned one—especially when thePAGEREFtab remained embedded inside a text run.Proposed solution
computeTabStops()now seeds the 0.5″ default grid from 0 twips whenever a paragraph lacks start-aligned explicit stops (TOC scenario), but retains the original behavior for paragraphs that already define their own left tabs so existing documents aren’t disturbed.layout-bridgeremeasurement expand literal tab characters intoTabRuns, track the total tab count, and map the last N tabs to the N explicit right/center/decimal stops. That keeps the trailing TOC tab pointed at the right-aligned stop (and renders the leader) even when earlier default stops exist.Note
This PR depends on SD-2440.