Fix indentAllLines applying the indent more than once - #1767
Merged
blikblum merged 1 commit intoAug 18, 2026
Merged
Conversation
MahathirMohammadShuvo
force-pushed
the
fix-indent-all-lines-compounding
branch
from
August 18, 2026 08:28
e088074 to
ee95926
Compare
Contributor
Author
|
Updated the branch. While checking this against continued text I found the same root cause behind #1606, so the scope grew slightly: continued segments inherit the previous call's options, so the follow-on The description above has the before/after numbers. Fourth regression test added for it; the suite is green at 384/384. |
blikblum
approved these changes
Aug 18, 2026
Member
|
Please fix the conflict |
indentAllLines keeps the indent in effect after the first line, but nothing tracked that it had already been applied. nextSection() re-applied it on every page break, and the firstLine handler re-applied it on every paragraph, so the indent accumulated. Paragraphs stepped progressively further right, and lineWidth - which carries over between pages while addPage() resets document.x - shrank by the indent on every page break, until eventually no word could fit on a line and pagination ran away. Track whether the indent is currently applied and apply it only once. On a page break restore document.x alone, since lineWidth already accounts for the indent. Adds regression tests covering paragraphs, page breaks, and the orphan check path where the page break runs before firstLine.
MahathirMohammadShuvo
force-pushed
the
fix-indent-all-lines-compounding
branch
from
August 18, 2026 11:55
ee95926 to
5174d37
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What kind of change does this PR introduce?
Bug fix. Fixes #1606.
indentAllLineskeeps the indent in effect after the first line, but nothing tracked whether it had already been applied.nextSection()re-applied it on every page break, and thefirstLinehandler re-applied it on every paragraph, so the indent accumulated instead of staying put.With
width: 300,indent: 15,indentAllLines: true:lineWidthafter successive page breakslineWidthcarries over between pages whileaddPage()resetsdocument.x, so subtracting the indent again on every page break narrowed the text column further and further. With enough pages it reaches zero, no word fits on a line, and pagination runs away — that reproduces as an out-of-memory crash.This is a regression from the fix for #1686, which added the indent restore in
nextSection()without accounting for thefirstLinehandler having already applied it.Continued text (#1606)
Continued segments inherit the previous call's options, so a follow-on
text()is alsoindentAllLinesand took the same early return — which meant the continuation offset was never taken back off and every line of the continued segment sat at the offset where the previous segment happened to end:lineWidth104.9lineWidth285The continuation offset belongs to the first line of a segment only, so it is now taken back off after that line while the paragraph indent stays on.
Checklist:
Four regression tests added to
tests/unit/line_wrapper.spec.js, covering paragraphs, page breaks, the orphan check path where the page break runs beforefirstLine, and continued text. All four fail against the currentlib/and pass with the fix. Full unit suite passes, 384/384.