Expose page indices changed by an edit
This commit is contained in:
1 parent
e55b44beac
commit
247cc8bd37
2 files changed
+22
No files matched your search
@@ -385,6 +385,8 @@ pub struct Layout {
|
|||||||
pub checkpoints: Vec<Checkpoint>,
|
pub checkpoints: Vec<Checkpoint>,
|
||||||
/// Number of pages whose content had to be rebuilt by the last edit.
|
/// Number of pages whose content had to be rebuilt by the last edit.
|
||||||
pub recomputed_pages: usize,
|
pub recomputed_pages: usize,
|
||||||
|
/// Page indices whose sealed hash changed in the last edit.
|
||||||
|
pub changed_pages: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout {
|
impl Layout {
|
||||||
@@ -534,11 +536,13 @@ impl Engine {
|
|||||||
output.shipout(page, index + 1);
|
output.shipout(page, index + 1);
|
||||||
page.seal_in_place();
|
page.seal_in_place();
|
||||||
}
|
}
|
||||||
|
let pages_len = pages.len();
|
||||||
Self {
|
Self {
|
||||||
layout: Layout {
|
layout: Layout {
|
||||||
pages,
|
pages,
|
||||||
checkpoints,
|
checkpoints,
|
||||||
recomputed_pages: 0,
|
recomputed_pages: 0,
|
||||||
|
changed_pages: (0..pages_len).collect(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -555,10 +559,16 @@ impl Engine {
|
|||||||
self.layout.recomputed_pages
|
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<String>) {
|
pub fn edit(&mut self, document: &Document, unit_id: UnitId, source: impl Into<String>) {
|
||||||
let Some(unit_index) = document.units.iter().position(|unit| unit.id == unit_id) else {
|
let Some(unit_index) = document.units.iter().position(|unit| unit.id == unit_id) else {
|
||||||
self.layout = Self::layout(document).layout;
|
self.layout = Self::layout(document).layout;
|
||||||
self.layout.recomputed_pages = self.layout.pages.len();
|
self.layout.recomputed_pages = self.layout.pages.len();
|
||||||
|
self.layout.changed_pages = (0..self.layout.pages.len()).collect();
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let mut next = document.clone();
|
let mut next = document.clone();
|
||||||
@@ -728,10 +738,18 @@ impl Engine {
|
|||||||
rebuilt += 1;
|
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 {
|
self.layout = Layout {
|
||||||
pages,
|
pages,
|
||||||
checkpoints,
|
checkpoints,
|
||||||
recomputed_pages: rebuilt,
|
recomputed_pages: rebuilt,
|
||||||
|
changed_pages,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -769,6 +787,7 @@ mod tests {
|
|||||||
assert!(engine.pages().len() >= 2);
|
assert!(engine.pages().len() >= 2);
|
||||||
engine.edit(&document, 5, "edited second page");
|
engine.edit(&document, 5, "edited second page");
|
||||||
assert_eq!(engine.recomputed_pages(), 1);
|
assert_eq!(engine.recomputed_pages(), 1);
|
||||||
|
assert_eq!(engine.changed_pages(), &[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ insertions, math lists, font metrics) are not executed.
|
|||||||
Route D is a TeX-compatible execution/layout core designed for incremental
|
Route D is a TeX-compatible execution/layout core designed for incremental
|
||||||
operation from the start. It does **not** embed pdfTeX, XeTeX or Tectonic.
|
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)
|
## M0 scope (this spike)
|
||||||
|
|
||||||
`crates/texrra-tex-core` currently provides:
|
`crates/texrra-tex-core` currently provides:
|
||||||
|
|||||||
Reference in new issue
Block a user