Skip to content

Fix format state reporting relative em font size for heading elements - #3419

Draft
JiuqingSong with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-font-size-in-h2-element
Draft

Fix format state reporting relative em font size for heading elements#3419
JiuqingSong with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-font-size-in-h2-element

Conversation

Copilot AI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

When cursor/selection is inside a heading element (h1–h6), getFormatState() returns the raw relative value (e.g. 1.5em for h2) instead of an absolute pt size, because the heading's default style is stored verbatim in the paragraph decorator format and px2Pt only converts px units.

Root cause

fontSizeFormatHandler stores the raw defaultStyle.fontSize value (e.g. '1.5em' from defaultContentModelFormatMap) without normalization when there is no inline element.style.fontSize. In retrieveModelFormatState, this relative value from the decorator overrides the container's resolved absolute font size in currentFormat, and then passes through px2Pt unchanged.

Fix

retrieveModelFormatState.ts — Before the final px2Pt call, resolve any remaining relative em/% font size against the container's computed font size (obtained from domHelper.getContainerFormat()):

formatState.fontSize = '1.5em'
containerFormat.fontSize = '16px'
→ 1.5 × 16 = 24px → 18pt  ✓

If no domHelper is available (legacy adapter path, unit tests without a DOM), the value is left as-is — no regression.

retrieveModelFormatStateTest.ts — Three new cases:

  • em decorator format + domHelper → resolves to absolute pt (1.5em × 16px = 18pt)
  • em decorator format, no domHelper → graceful fallback, value unchanged
  • % decorator format + domHelper → resolves to absolute pt (150% × 16px = 18pt)

Copilot AI changed the title [WIP] Fix font size in h2 element formatting Fix format state reporting relative em font size for heading elements Jul 29, 2026
Copilot AI requested a review from JiuqingSong July 29, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

format state shows fontSize:1.5em in h2 element

2 participants