diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-09-18 10:49:22 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-09-18 10:51:29 +0200 |
| commit | 72d8a9c89aa9306518edd6484d2097d40ab28d19 (patch) | |
| tree | 78a2a124b8bde29dab809106b29c74b68c065d15 | |
| parent | 25613cfaf3a20f737ac347f7d7144a5dcaa709a5 (diff) | |
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
| -rw-r--r-- | crates/typst-library/src/layout/flow.rs | 4 | ||||
| -rw-r--r-- | crates/typst/src/model/introspect.rs | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/crates/typst-library/src/layout/flow.rs b/crates/typst-library/src/layout/flow.rs index 802154a0..796b1ac8 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 90598679..ebf2ab75 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`. |
