diff --git a/crates/typst-library/src/layout/grid/resolve.rs b/crates/typst-library/src/layout/grid/resolve.rs index 42df8953b..acb588e95 100644 --- a/crates/typst-library/src/layout/grid/resolve.rs +++ b/crates/typst-library/src/layout/grid/resolve.rs @@ -680,6 +680,10 @@ pub struct CellGrid<'a> { pub headers: Vec>, /// The repeatable footers of this grid. pub footers: Vec>, + /// Footers sorted by order of when they start repeating, or should + /// otherwise be laid out for the first time (even if only once, for + /// non-repeating footers). + pub sorted_footers: Vec>, /// Whether this grid has gutters. pub has_gutter: bool, } @@ -749,6 +753,9 @@ impl<'a> CellGrid<'a> { rows.pop(); } + let footers: Vec> = footer.into_iter().collect(); + let sorted_footers = simulate_footer_repetition(&footers); + Self { cols, rows, @@ -2394,3 +2401,50 @@ fn skip_auto_index_through_fully_merged_rows( } } } + +/// Generates a vector where all footers are sorted ahead of time by the points +/// at which they start repeating. When a new footer is about to be laid out, +/// conflicting footers which come before it in this vector must stop +/// repeating. +fn simulate_footer_repetition( + footers: &[Repeatable