-
Notifications
You must be signed in to change notification settings - Fork 121
fix: correct tab leader from/to bounds when effectiveIndent is applied #2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
caio-pizzol
merged 8 commits into
superdoc-dev:main
from
roncallyt:fix/toc-leaders-overlap
Mar 23, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e07ed2e
fix: correct tab leader from/to bounds when effectiveIndent is applied
roncallyt 1ab6455
fix: use absolute coordinates for tab leader from/to bounds
roncallyt 44cc296
test: fix leader positioning assertions and deduplicate tests
roncallyt 64cfc33
test: fix unnecessary check and avoid ! assertion
roncallyt 2d15f16
fix: save leader reference on push to avoid wrong leader mutation
roncallyt 9e6bf3e
fix: use absolute coordinates for tab leaders in remeasure path
roncallyt e2e59cd
fix: update inline tab leader boundary after alignment resolution
roncallyt db63994
Merge branch 'main' into fix/toc-leaders-overlap
caio-pizzol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ import { | |
| type TableBorders, | ||
| type TableBorderValue, | ||
| effectiveTableCellSpacing, | ||
| LeaderDecoration, | ||
| } from '@superdoc/contracts'; | ||
| import type { WordParagraphLayoutOutput } from '@superdoc/word-layout'; | ||
| import { | ||
|
|
@@ -1093,6 +1094,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| let hasSeenTextRun = false; | ||
| let tabStopCursor = 0; | ||
| let pendingTabAlignment: { target: number; val: TabStop['val'] } | null = null; | ||
| let pendingLeader: LeaderDecoration | null = null; | ||
| let pendingRunSpacing = 0; | ||
| // Remember the last applied tab alignment so we can clamp end-aligned | ||
| // segments to the exact target after measuring to avoid 1px drift. | ||
|
|
@@ -1168,10 +1170,19 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| startX = Math.max(0, target); | ||
| } | ||
|
|
||
| // Update pending leader to end where aligned content begins | ||
| if (pendingLeader) { | ||
| const effectiveIndent = lines.length === 0 ? indentLeft + rawFirstLineOffset : indentLeft; | ||
| pendingLeader.to = startX + effectiveIndent; | ||
| pendingLeader = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line sets |
||
| } | ||
|
|
||
| currentLine.width = roundValue(startX); | ||
| // Track alignment used for post-segment clamping | ||
| lastAppliedTabAlign = { target, val }; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
|
|
||
| return startX; | ||
| }; | ||
|
|
||
|
|
@@ -1321,6 +1332,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| } | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
| pendingRunSpacing = 0; | ||
| continue; | ||
|
|
@@ -1377,6 +1389,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| }; | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
| pendingRunSpacing = 0; | ||
| continue; | ||
|
|
@@ -1386,6 +1399,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| if (isTabRun(run)) { | ||
| // Clear any previous tab group when we encounter a new tab | ||
| activeTabGroup = null; | ||
| pendingLeader = null; | ||
|
|
||
| // Initialize line if needed | ||
| if (!currentLine) { | ||
|
|
@@ -1419,15 +1433,16 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| currentLine.maxFontSize = Math.max(currentLine.maxFontSize, 12); | ||
| currentLine.toRun = runIndex; | ||
| currentLine.toChar = 1; // tab is a single character | ||
| let currentLeader: LeaderDecoration | null = null; | ||
|
|
||
| // Emit leader decoration if requested | ||
| if (stop && stop.leader && stop.leader !== 'none') { | ||
| const leaderStyle: 'heavy' | 'dot' | 'hyphen' | 'underscore' | 'middleDot' = stop.leader; | ||
| const relativeTarget = clampedTarget - effectiveIndent; | ||
| const from = Math.min(originX, relativeTarget); | ||
| const to = Math.max(originX, relativeTarget); | ||
| const from = Math.min(originX + effectiveIndent, clampedTarget); | ||
| const to = Math.max(originX + effectiveIndent, clampedTarget); | ||
| if (!currentLine.leaders) currentLine.leaders = []; | ||
| currentLine.leaders.push({ from, to, style: leaderStyle }); | ||
| currentLeader = { from, to, style: leaderStyle }; | ||
| currentLine.leaders.push(currentLeader); | ||
| } | ||
|
|
||
| if (stop) { | ||
|
|
@@ -1455,6 +1470,11 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| groupStartX = Math.max(0, relativeTarget - beforeDecimal); | ||
| } | ||
|
|
||
| // Update current leader "to" ensuring leaders end where right-aligned content begins | ||
| if (currentLeader) { | ||
| currentLeader.to = groupStartX + effectiveIndent; | ||
| } | ||
|
|
||
| // Set up active tab group for subsequent run processing | ||
| activeTabGroup = { | ||
| measure: groupMeasure, | ||
|
|
@@ -1471,12 +1491,14 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
|
|
||
| // Don't set pendingTabAlignment - we're using activeTabGroup instead | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| } else { | ||
| // For start-aligned tabs, use the existing pendingTabAlignment mechanism | ||
| pendingTabAlignment = { target: clampedTarget - effectiveIndent, val: stop.val }; | ||
| } | ||
| } else { | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| } | ||
| pendingRunSpacing = 0; | ||
| continue; | ||
|
|
@@ -1553,6 +1575,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
| activeTabGroup = null; | ||
|
|
||
|
|
@@ -1704,6 +1727,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
|
|
||
| // Start new line with the annotation (body line, so use bodyContentWidth for hanging indent) | ||
|
|
@@ -1808,6 +1832,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
|
|
||
| // Body line, so use bodyContentWidth for hanging indent | ||
|
|
@@ -1922,6 +1947,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| lastAppliedTabAlign = null; | ||
| activeTabGroup = null; | ||
|
|
||
|
|
@@ -2005,6 +2031,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| currentLine = null; | ||
| } | ||
|
|
||
|
|
@@ -2072,6 +2099,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| currentLine = null; | ||
| } | ||
| } else if (isLastChunk) { | ||
|
|
@@ -2218,6 +2246,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
|
|
||
| // Body line, so use bodyContentWidth for hanging indent | ||
| currentLine = { | ||
|
|
@@ -2280,6 +2309,7 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| lines.push(completedLine); | ||
| tabStopCursor = 0; | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| currentLine = null; | ||
| // advance past space | ||
| charPosInRun = wordEndNoSpace + 1; | ||
|
|
@@ -2341,6 +2371,8 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
|
|
||
| if (!isLastSegment) { | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
|
|
||
| if (!currentLine) { | ||
| currentLine = { | ||
| fromRun: runIndex, | ||
|
|
@@ -2376,16 +2408,18 @@ async function measureParagraphBlock(block: ParagraphBlock, maxWidth: number): P | |
| pendingTabAlignment = { target: clampedTarget - effectiveIndent, val: stop.val }; | ||
| } else { | ||
| pendingTabAlignment = null; | ||
| pendingLeader = null; | ||
| } | ||
|
|
||
| // Emit leader decoration if requested | ||
| if (stop && stop.leader && stop.leader !== 'none' && stop.leader !== 'middleDot') { | ||
| const leaderStyle: 'heavy' | 'dot' | 'hyphen' | 'underscore' = stop.leader; | ||
| const relativeTarget = clampedTarget - effectiveIndent; | ||
| const from = Math.min(originX, relativeTarget); | ||
| const to = Math.max(originX, relativeTarget); | ||
| const from = Math.min(originX + effectiveIndent, clampedTarget); | ||
| const to = Math.max(originX + effectiveIndent, clampedTarget); | ||
| if (!currentLine.leaders) currentLine.leaders = []; | ||
| currentLine.leaders.push({ from, to, style: leaderStyle }); | ||
| const leader: LeaderDecoration = { from, to, style: leaderStyle }; | ||
| currentLine.leaders.push(leader); | ||
| pendingLeader = leader; | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.