Skip to content

SD-2447 - fix: tab stop computation and alignment for TOC styles#2731

Open
chittolinag wants to merge 13 commits intomainfrom
gabriel/sd-2447-bug-toc-renders-with-incorrect-formatting-after-document
Open

SD-2447 - fix: tab stop computation and alignment for TOC styles#2731
chittolinag wants to merge 13 commits intomainfrom
gabriel/sd-2447-bug-toc-renders-with-incorrect-formatting-after-document

Conversation

@chittolinag
Copy link
Copy Markdown
Contributor

@chittolinag chittolinag commented Apr 7, 2026

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 \t jumped 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 the PAGEREF tab remained embedded inside a text run.

Proposed solution

  1. 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.
  2. Both the DOM measurer and layout-bridge remeasurement expand literal tab characters into TabRuns, 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.

@linear
Copy link
Copy Markdown

linear bot commented Apr 7, 2026

@chittolinag chittolinag changed the title fix: tab stop computation and alignment for TOC styles SD-2447 - fix: tab stop computation and alignment for TOC styles Apr 7, 2026
…-tablesfigures-toc' into gabriel/sd-2447-bug-toc-renders-with-incorrect-formatting-after-document
@chittolinag chittolinag marked this pull request as ready for review April 7, 2026 17:02
@chittolinag chittolinag requested review from caio-pizzol and harbournick and removed request for harbournick April 7, 2026 17:02
Copy link
Copy Markdown

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

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: 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@chittolinag chittolinag requested a review from tupizz April 7, 2026 17:58
chittolinag and others added 7 commits April 8, 2026 14:41
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
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