Hash rendered page content instead of source metadata

This commit is contained in:
gloamxun committed 2026-10-20 21:53:51 +08:00
1 parent 2c4d968659
commit f0e5f14a8c
2 files changed
+24 -3

No files matched your search

+19 -1
View File
@@ -578,7 +578,6 @@ impl Page {
self.insertions.hash(&mut hasher);
self.marks.hash(&mut hasher);
self.floats.hash(&mut hasher);
self.sources.hash(&mut hasher);
self.hash = hasher.finish();
}
}
@@ -1171,6 +1170,9 @@ impl Engine {
{
pages.push(current);
}
for page in &mut pages {
page.sources.clear();
}
for (index, unit) in next.units.iter().enumerate() {
if let Some(checkpoint) = checkpoints.get(index)
&& let Some(page) = pages.get_mut(checkpoint.page_index)
@@ -1346,6 +1348,22 @@ mod tests {
assert_eq!(with_top_skip.layout.pages.len(), 2);
}
#[test]
fn editing_keeps_earlier_page_sources_stable() {
let mut document = Document::new(
100,
vec![
Unit::paragraph(1, "a ".repeat(200)),
Unit::paragraph(2, "b ".repeat(200)),
],
);
let mut engine = Engine::layout(&document);
let before = engine.pages()[0].hash;
engine.edit(&document, 2, "c ".repeat(200));
assert_eq!(engine.pages()[0].hash, before);
document.units[1].source = "c ".repeat(200);
}
#[test]
fn vertical_penalty_can_force_a_page_break() {
let unit = Unit {