Repository navigation
Fix sticky blocks at the top of blocks and pages - #5581
Merged
Merged
Conversation
- Use 'regions.may_progress()' to determine whether to remain sticky - Use 'stickable' to keep the decision for the first sticky block for all the others.
1 task done
PgBiel
marked this pull request as ready for review
December 16, 2024 23:16
laurmaedje
enabled auto-merge
December 17, 2024 09:38
1 task done
Dikluwe
pushed a commit
to Dikluwe/typst-crystalline
that referenced
this pull request
Sep 12, 2026
Co-authored-by: Laurenz <[email protected]>
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.
Fixes #5296
Normally, sticky blocks at the top of a page have their stickiness disabled, as just migrating to the next page when the frame attached to the sticky block goes to the next page would lead us back to the exact same situation (sticky block at the top of the page again, and the attached frame wouldn't fit again), leading to an infinite loop.
However, this check was done too naively, by just checking if we're the first frame (not even necessarily at the very top) of the flow. But a block also contains a flow, and being at the top of a block isn't a problem, unless the block contains the whole page.
So, this PR changes it so the first sticky block is only disabled if
regions.may_progress()is false.On consecutive sticky blocks
Now, onto something (conceptually) unrelated to the original issue, but which is related to how the fix works.
As shown in #5296, just performing this change leads the
block-sticky-manytest to fail (see the before/after below):This is because, when the first sticky block is placed in each page, it itself is disabled, but causes all upcoming sticky blocks to be enabled, since
regions.may_progress()becomes true for them - and that makes sense, since the first sticky block won't be there in the next page, so migrating the second or third sticky block is (theoretically) OK since the amount of available space will increase (no infinite loop).However, the new output is clearly not the ideal output, as the old test output shows that it would be impossible to fit all of the sticky blocks and the attached frame in the same page anyway, so might as well group up those that don't fit in a single page, instead of spreading them over multiple almost fully empty pages.
The solution
Right now, this PR implements the following solution: if the first sticky block is disabled, all upcoming consecutive sticky blocks are also disabled, so they are all laid consecutively in the same page. However, this has the undesirable outcome of fully disabling stickiness for this case, making it possible for the attached frame to be alone at the top of the page, though that was also how it worked before, so problems here wouldn't be regressions (and the test passes again).
However, I'm experimenting with an alternative approach, so this PR will remain a draft for now.
(EDIT: It was regarded that this case only presents a problem if sticky blocks + attached frame don't fit in the same page together, in which case stickiness is already violated anyway, so the case is pathological. Therefore, the above solution is kept, and the existing 0.12 behavior is not regressed.)
TODO
regions.may_progress(); added a test to confirm)