From e4bbe471a7b87c8ef5cee23c483538d89e86e6c2 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Wed, 9 Apr 2025 14:55:41 -0300 Subject: [PATCH] set snapshot when laying out new headers - Still need to detect when this doesn't make sense, e.g. in the last region, or right before a footer... --- crates/typst-layout/src/grid/repeated.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/typst-layout/src/grid/repeated.rs b/crates/typst-layout/src/grid/repeated.rs index 1402ce621..bd76cdda4 100644 --- a/crates/typst-layout/src/grid/repeated.rs +++ b/crates/typst-layout/src/grid/repeated.rs @@ -357,8 +357,9 @@ impl<'a> GridLayouter<'a> { self.unbreakable_rows_left += total_header_row_count(headers.iter().map(Repeatable::unwrap)); + let initial_row_count = self.lrows.len(); let placing_at_the_start = - skipped_region || self.lrows.len() == self.current_header_rows; + skipped_region || initial_row_count == self.current_header_rows; for header in headers { let header_height = self.layout_header_rows(header.unwrap(), engine, 0)?; @@ -382,6 +383,12 @@ impl<'a> GridLayouter<'a> { self.current_header_rows = self.lrows.len(); } + // Remove new headers at the end of the region if upcoming child doesn't fit. + // TODO: Short lived if footer comes afterwards + if !short_lived { + self.lrows_orphan_snapshot = Some(initial_row_count); + } + Ok(()) }