Skip to content

Fix sticky blocks at the top of blocks and pages - #5581

Merged
laurmaedje merged 6 commits into
mainfrom
fix-sticky-blocks-at-top
Dec 17, 2024
Merged

laurmaedje merged 6 commits into
mainfrom
fix-sticky-blocks-at-top

Conversation

@PgBiel

@PgBiel PgBiel commented Dec 15, 2024 •

Copy link
Copy Markdown
Contributor

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-many test to fail (see the before/after below):

#set page(height: 80pt)
#set block(sticky: true)
#block[A]
#block[B]
#block[C]
#block[D]
E
#block[F]
#block[G]

block-sticky-many test: page with A B C, page with D E, page with F G (before), page with A, page with B, page with C D E, page with F G (after)

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

  • Perhaps consider weak spacing for 'stickable' (it already doesn't matter for regions.may_progress(); added a test to confirm)
  • Consider alternative solution for consecutive sticky blocks at the top of a page (considered, decided to keep the above solution)

- 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.
@PgBiel
PgBiel marked this pull request as ready for review December 16, 2024 23:16
@laurmaedje
laurmaedje enabled auto-merge December 17, 2024 09:38
@laurmaedje
laurmaedje added this pull request to the merge queue Dec 17, 2024
Merged via the queue into main with commit 60f246e Dec 17, 2024
@laurmaedje
laurmaedje deleted the fix-sticky-blocks-at-top branch December 17, 2024 09:49
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
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.

Block sticky parameter doesn't work at the start of block

2 participants