From a10e3324c21daf25fd8e8fc5336aa72718a87e47 Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Tue, 11 Jun 2024 05:14:26 -0400 Subject: [PATCH] interrupt_styles: Check all potential style matches (#4345) --- crates/typst/src/realize/behaviour.rs | 6 ++++++ crates/typst/src/realize/mod.rs | 9 ++++++--- tests/ref/issue-4340-set-document-and-page.png | Bin 0 -> 222 bytes tests/suite/layout/page.typ | 8 ++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/ref/issue-4340-set-document-and-page.png diff --git a/crates/typst/src/realize/behaviour.rs b/crates/typst/src/realize/behaviour.rs index de6fb8a0e..945d2f2a9 100644 --- a/crates/typst/src/realize/behaviour.rs +++ b/crates/typst/src/realize/behaviour.rs @@ -231,7 +231,13 @@ impl<'a> Default for BehavedBuilder<'a> { /// A sequence of elements with associated styles. #[derive(Clone, PartialEq, Hash)] pub struct StyleVec { + /// The elements themselves. elements: EcoVec, + /// A run-length encoded list of style lists. + /// + /// Each element is a (styles, count) pair. Any elements whose + /// style falls after the end of this list is considered to + /// have an empty style list. styles: EcoVec<(Styles, usize)>, } diff --git a/crates/typst/src/realize/mod.rs b/crates/typst/src/realize/mod.rs index 40e9a9b06..caad222a4 100644 --- a/crates/typst/src/realize/mod.rs +++ b/crates/typst/src/realize/mod.rs @@ -220,16 +220,19 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { { bail!(span, "document set rules must appear before any content"); } - } else if let Some(Some(span)) = local.interruption::() { + } + if let Some(Some(span)) = local.interruption::() { if self.doc.is_none() { bail!(span, "page configuration is not allowed inside of containers"); } self.interrupt_page(outer, false)?; - } else if local.interruption::().is_some() + } + if local.interruption::().is_some() || local.interruption::().is_some() { self.interrupt_par()?; - } else if local.interruption::().is_some() + } + if local.interruption::().is_some() || local.interruption::().is_some() || local.interruption::().is_some() { diff --git a/tests/ref/issue-4340-set-document-and-page.png b/tests/ref/issue-4340-set-document-and-page.png new file mode 100644 index 0000000000000000000000000000000000000000..4737d2eb5ea66770edb80f7070d986a872572c46 GIT binary patch literal 222 zcmeAS@N?(olHy`uVBq!ia0vp^6+mpj0VEjyvpnPnQcFEu978H@B}bS#G$dYm6xi*q zE4Ouql-PO4B>gxi`|k7^N}acTmdroO>Q%YA>$A|ah^Hl0{vo}yTnq`BqA$g#UEX?XT{-99pso4;R=qi} z$