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
This commit is contained in:
Laurenz 2023-09-18 10:49:22 +02:00
parent 25613cfaf3
commit 72d8a9c89a
2 changed files with 5 additions and 1 deletions

View File

@ -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);
}

View File

@ -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`.