Skip to content

fix: correct spacing for paragraphs with borders/shades#2586

Merged
caio-pizzol merged 7 commits intomainfrom
caio-pizzol/SD-2106-paragraph-border-spacing
Mar 28, 2026
Merged

fix: correct spacing for paragraphs with borders/shades#2586
caio-pizzol merged 7 commits intomainfrom
caio-pizzol/SD-2106-paragraph-border-spacing

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

No description provided.

@linear
Copy link
Copy Markdown

linear bot commented Mar 27, 2026

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: 1d0ae93d45

ℹ️ 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".

johanneswilm and others added 6 commits March 28, 2026 06:33
Per ECMA-376 §17.3.1.42, paragraph border space is measured from
the text edge "ignoring any spacing above/below". This means border
expansion should overlap with spacingBefore/After, not stack on top.

- Reduce top border expansion by the amount spacingBefore already covers
- Reduce effective spacingAfter by the bottom border expansion
- Subtract border expansion from sliceLines available height to prevent
  page-bottom overflow
- Include border expansion in keepLines height calculation
Three fixes from self-review:

- fragment.y now uses extraTop (overlap-adjusted) instead of full
  borderExpansion.top, so cursorY reaches the visual bottom exactly
- Track spacingAppliedThisFragment to avoid under-counting border
  expansion on continuation fragments after page breaks
- keepLines fitsOnBlankPage uses overlap model (max instead of add)
  to avoid unnecessary page breaks for bordered paragraphs
borderExpansion was declared inside the while loop but referenced
in the spacingAfter block outside it, causing a ReferenceError.
Move it before the loop so it's accessible in both places.
Layout engine:
- Detect between-border groups by comparing adjacent paragraph border
  hashes. When borders match, suppress top expansion and reclaim
  previous paragraph's bottom expansion.
- Border expansion is additive with spacing for non-grouped paragraphs
  (matches Word behavior).
- Add lastParagraphBorderHash to PageState for group tracking.

Renderer (group-analysis.ts):
- Remove requirement for `between` border element to be present for
  grouping. Per ECMA-376 §17.3.1.5, grouping occurs when all border
  properties are identical — a between border is optional.
- When no between border is defined, suppress bottom/top borders
  and render as a single continuous box.
…tween element

The test expected no grouping when `between` border is absent. Updated
to expect grouping with suppressBottomBorder per ECMA-376 §17.3.1.5:
identical borders form a group regardless of whether a between border
is defined.
@caio-pizzol caio-pizzol force-pushed the caio-pizzol/SD-2106-paragraph-border-spacing branch from cbcb1ee to 5d8880a Compare March 28, 2026 09:34
layout-engine cannot import from pm-adapter (boundary removed in #2618).
Define PX_PER_PT locally, same as border-layer.ts does.
@caio-pizzol caio-pizzol force-pushed the caio-pizzol/SD-2106-paragraph-border-spacing branch from 0203512 to 2b6014d Compare March 28, 2026 09:45
@caio-pizzol caio-pizzol merged commit 70a2dbe into main Mar 28, 2026
48 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/SD-2106-paragraph-border-spacing branch March 28, 2026 10:33
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 28, 2026

🎉 This PR is included in vscode-ext v1.1.0-next.35

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 28, 2026

🎉 This PR is included in superdoc v1.24.0-next.34

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 28, 2026

🎉 This PR is included in superdoc-cli v0.5.0-next.34

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot bot commented Mar 28, 2026

🎉 This PR is included in superdoc-sdk v1.3.0-next.34

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