diff --git a/crates/typst-layout/src/flow/collect.rs b/crates/typst-layout/src/flow/collect.rs index 2c14f7a37..fb0a8086e 100644 --- a/crates/typst-layout/src/flow/collect.rs +++ b/crates/typst-layout/src/flow/collect.rs @@ -457,6 +457,7 @@ impl<'a> MultiChild<'a> { regions: Regions, ) -> SourceResult<(Frame, Option>)> { let fragment = self.layout_full(engine, regions)?; + let exist_non_empty_frame = fragment.iter().any(|f| !f.is_empty()); // Extract the first frame. let mut frames = fragment.into_iter(); @@ -466,6 +467,7 @@ impl<'a> MultiChild<'a> { let mut spill = None; if frames.next().is_some() { spill = Some(MultiSpill { + exist_non_empty_frame, multi: self, full: regions.full, first: regions.size.y, @@ -537,6 +539,7 @@ fn layout_multi_impl( /// The spilled remains of a `MultiChild` that broke across two regions. #[derive(Debug, Clone)] pub struct MultiSpill<'a, 'b> { + pub(super) exist_non_empty_frame: bool, multi: &'b MultiChild<'a>, first: Abs, full: Abs, diff --git a/crates/typst-layout/src/flow/distribute.rs b/crates/typst-layout/src/flow/distribute.rs index f504d22e7..d12b1ff68 100644 --- a/crates/typst-layout/src/flow/distribute.rs +++ b/crates/typst-layout/src/flow/distribute.rs @@ -283,6 +283,13 @@ impl<'a, 'b> Distributor<'a, 'b, '_, '_, '_> { // Lay out the block. let (frame, spill) = multi.layout(self.composer.engine, self.regions)?; + if frame.is_empty() && spill.as_ref().is_some_and(|s| s.exist_non_empty_frame) { + // If the first frame is empty, but there are non-empty frames in + // the spill, the whole child should be put in the next region to + // avoid any invisible orphans at the end of this region. + return Err(Stop::Finish(false)); + } + self.frame(frame, multi.align, multi.sticky, true)?; // If the block didn't fully fit into the current region, save it into diff --git a/tests/ref/issue-2914-block-fill-skip-nested.png b/tests/ref/issue-2914-block-fill-skip-nested.png index d7b1aa7d7..0dcbd6d85 100644 Binary files a/tests/ref/issue-2914-block-fill-skip-nested.png and b/tests/ref/issue-2914-block-fill-skip-nested.png differ diff --git a/tests/ref/issue-2914-block-height-cut-off.png b/tests/ref/issue-2914-block-height-cut-off.png index 1c4d57d2a..559af35de 100644 Binary files a/tests/ref/issue-2914-block-height-cut-off.png and b/tests/ref/issue-2914-block-height-cut-off.png differ diff --git a/tests/ref/issue-6125-block-place-width-limited.png b/tests/ref/issue-6125-block-place-width-limited.png index bf61465ef..28c564570 100644 Binary files a/tests/ref/issue-6125-block-place-width-limited.png and b/tests/ref/issue-6125-block-place-width-limited.png differ