From 247cc8bd37f06bfed7c556648a7532cc0cb55bbe Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 13:08:35 +0800 Subject: [PATCH] Expose page indices changed by an edit --- crates/texrra-tex-core/src/lib.rs | 19 +++++++++++++++++++ docs/TEX_CORE.md | 3 +++ 2 files changed, 22 insertions(+) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 46a9de6..50c7467 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -385,6 +385,8 @@ pub struct Layout { pub checkpoints: Vec, /// Number of pages whose content had to be rebuilt by the last edit. pub recomputed_pages: usize, + /// Page indices whose sealed hash changed in the last edit. + pub changed_pages: Vec, } impl Layout { @@ -534,11 +536,13 @@ impl Engine { output.shipout(page, index + 1); page.seal_in_place(); } + let pages_len = pages.len(); Self { layout: Layout { pages, checkpoints, recomputed_pages: 0, + changed_pages: (0..pages_len).collect(), }, } } @@ -555,10 +559,16 @@ impl Engine { self.layout.recomputed_pages } + /// Page indices whose sealed hash changed during the last edit. + pub fn changed_pages(&self) -> &[usize] { + &self.layout.changed_pages + } + pub fn edit(&mut self, document: &Document, unit_id: UnitId, source: impl Into) { let Some(unit_index) = document.units.iter().position(|unit| unit.id == unit_id) else { self.layout = Self::layout(document).layout; self.layout.recomputed_pages = self.layout.pages.len(); + self.layout.changed_pages = (0..self.layout.pages.len()).collect(); return; }; let mut next = document.clone(); @@ -728,10 +738,18 @@ impl Engine { rebuilt += 1; } } + let changed_pages = (checkpoint.page_index..pages.len()) + .filter(|index| { + old_pages + .get(*index) + .is_none_or(|old| old.hash != pages[*index].hash) + }) + .collect(); self.layout = Layout { pages, checkpoints, recomputed_pages: rebuilt, + changed_pages, }; } } @@ -769,6 +787,7 @@ mod tests { assert!(engine.pages().len() >= 2); engine.edit(&document, 5, "edited second page"); assert_eq!(engine.recomputed_pages(), 1); + assert_eq!(engine.changed_pages(), &[1]); } #[test] diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 7b744e3..dd15f7f 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -15,6 +15,9 @@ insertions, math lists, font metrics) are not executed. Route D is a TeX-compatible execution/layout core designed for incremental operation from the start. It does **not** embed pdfTeX, XeTeX or Tectonic. + +- `Layout::changed_pages` / `Engine::changed_pages()` list the page indices + whose sealed hash changed during the last edit. ## M0 scope (this spike) `crates/texrra-tex-core` currently provides: