Skip to content

fix: prevent text overlap when multi-column sections span pages (SD-1869)#2676

Open
luccas-harbour wants to merge 4 commits intomainfrom
luccas/sd-1869-bug-text-overlap-occurs-when-section-breaksmulti-column
Open

fix: prevent text overlap when multi-column sections span pages (SD-1869)#2676
luccas-harbour wants to merge 4 commits intomainfrom
luccas/sd-1869-bug-text-overlap-occurs-when-section-breaksmulti-column

Conversation

@luccas-harbour
Copy link
Copy Markdown
Contributor

Summary

  • Fix text overlap caused by the CSS "strut" (inherited browser-default 16px font-size) misaligning normal-flow inline children relative to absolutely-positioned tab segments inside line containers. Sets fontSize: '0' on line containers and restores explicit font sizes on child elements that need them (field annotations, math wrappers, empty-run spans).
  • Fix multi-column section overlap when columns have unequal heights by tracking maxCursorY across columns and using it as the starting Y for the next region.
  • Fix tab run measurement using actual font size instead of a hardcoded 12pt default.

The tab measurement code hardcoded `maxFontSize: 12` for tab-created lines and tab runs, causing incorrect line height calculations when the surrounding text used a different font size. This also adds `fontSize: '0'` to line styles to eliminate the CSS strut that caused baseline misalignment between normal-flow and absolutely-positioned (tab-aligned) children.
When a multi-column section's content spans multiple pages and columns have
unequal heights, the next section's content was positioned at the shorter
column's cursor Y instead of below all column content. This caused visible
text overlap on page 2.

Add maxCursorY to PageState to track the deepest Y reached across all
columns. startMidPageRegion now uses this value so the next section begins
below all column content.
…l lines

Lines with tab stops use absolute positioning for text segments, which
bypasses the CSS strut. Normal-flow lines inherit the browser's default
16px font-size, creating a strut that shifts text down ~1px via baseline
alignment. This made tab-indented first lines appear shifted up relative
to continuation lines.

Zero the line container's font-size to remove the strut, and restore
explicit font-size on the three child elements that inherit rather than
set their own: empty-run caret placeholder (lineHeight), math run
wrapper (run height), and field annotation wrapper (16px fallback).
@linear
Copy link
Copy Markdown

linear bot commented Apr 1, 2026

Verifies that mid-page column transitions start below the tallest
column when columns have unequal heights. Uses a 3-col → 2-col
transition to exercise the maxCursorY tracking without triggering
the new-page guard (columnIndexBefore >= newColumns.count).
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

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

@luccas-harbour the overlap fix works — pushed a regression test for it (e859c96).

side finding: the ECMA spec says continuous section breaks should balance content evenly across columns (like Word does — 6 paragraphs in 2 columns = 3+3). SuperDoc fills column 1 first, which is why multi-column docs look different from Word. this is pre-existing, not on this PR — filed SD-2452 for it.

left one inline comment.

// matter much: MathML has its own internal scaling, and the plain-text
// fallback just needs a non-zero size. Don't rely on this for precise
// typographic sizing.
wrapper.style.fontSize = `${run.height}px`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

run.height can be 80-100px for tall math expressions (fractions, equation arrays). that gets used as the font size here, which would make the plain-text fallback huge. a fixed value like 24px or the paragraph's font size would be safer — worth changing?

@caio-pizzol caio-pizzol self-requested a review April 3, 2026 11:25
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

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

feel free to merge after addressing last comment

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