From 72d8a9c89aa9306518edd6484d2097d40ab28d19 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 18 Sep 2023 10:49:22 +0200 Subject: [PATCH] Fix duplicate state manipulation The flow layouts footnotes twice in some cases, which messed up the Vt's locator state. Typically, we use `thing.measure` instead of `thing.layout` to prevent side effects, but in this case it was simpler to just undo the modification. A future layout engine rewrite should try to make this kind of error harder to make. Fixes #1597 --- crates/typst-library/src/layout/flow.rs | 4 ++++ crates/typst/src/model/introspect.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/typst-library/src/layout/flow.rs b/crates/typst-library/src/layout/flow.rs index 802154a02..796b1ac8d 100644 --- a/crates/typst-library/src/layout/flow.rs +++ b/crates/typst-library/src/layout/flow.rs @@ -617,6 +617,7 @@ impl FlowLayouter<'_> { } self.regions.size.y -= self.footnote_config.gap; + let checkpoint = vt.locator.clone(); let frames = FootnoteEntry::new(notes[k].clone()) .pack() .layout(vt, self.styles, self.regions.with_root(false))? @@ -637,6 +638,9 @@ impl FlowLayouter<'_> { self.regions.size.y -= item.height(); } + // Undo Vt modifications. + *vt.locator = checkpoint; + return Ok(false); } diff --git a/crates/typst/src/model/introspect.rs b/crates/typst/src/model/introspect.rs index 90598679b..ebf2ab751 100644 --- a/crates/typst/src/model/introspect.rs +++ b/crates/typst/src/model/introspect.rs @@ -111,7 +111,7 @@ cast! { /// [^1]: Well, we could with [`TrackedMut`](comemo::TrackedMut), but the /// overhead is quite high, especially since we need to save & undo the counting /// when only measuring. -#[derive(Default)] +#[derive(Default, Clone)] pub struct Locator<'a> { /// Maps from a hash to the maximum number we've seen for this hash. This /// number becomes the `disambiguator`.