Fix pageBreakBefore with unbreakable blocks#2927
Open
rstrand wants to merge 1 commit intobpampuch:masterfrom
Open
Fix pageBreakBefore with unbreakable blocks#2927rstrand wants to merge 1 commit intobpampuch:masterfrom
rstrand wants to merge 1 commit intobpampuch:masterfrom
Conversation
pageBreakBefore helpers like getFollowingNodesOnPage() returned incorrect results when unbreakable blocks moved to a new page, breaking the documented orphaned-children pattern. Node positions were not updated because _node back-references were only set on lines with tocItem or id. * always set _node on text lines and add tracking for image/SVG/canvas/QR/attachment nodes * exclude header/footer nodes from linearNodeList * fix attachments silently dropped inside unbreakable blocks
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.
I was trying to implement the documented orphaned-children pattern to prevent headings from being stranded at the bottom of a page:
This didn't work when the content following the heading was inside an
unbreakable: trueblock. The callback'sgetFollowingNodesOnPage()was returning the unbreakable block's nodes as still on the same page as the heading, even though they had moved to the next page. I also found that header/footer nodes were appearing in the results, further preventing thelength === 0check from ever being true.I tracked the cause down to a few issues:
_nodeback-references, whichaddFragment()uses to update positions when blocks move pages, were only set on lines withtocItemorid. I changed this to set_nodeon all text lines and added tracking for image, SVG, canvas, QR, and attachment nodes.Nodes from dynamic headers and footers were being pushed into
linearNodeList, which contaminatedgetFollowingNodesOnPage()and the other pageBreakBefore helpers with irrelevant nodes. I added a flag to suppress this duringaddDynamicRepeatable()processing.I also noticed that attachments inside unbreakable blocks were being silently dropped because
addFragment()had no case for the'attachment'item type.This PR addresses these and adds relevant test cases.