Replay paged edits with later insertions and keep zero parskip breakpoints
This commit is contained in:
1 parent
e632db02cf
commit
72f5436318
2 files changed
+108
-15
No files matched your search
@@ -839,11 +839,7 @@ fn document_nodes(
|
||||
let mut previous_paragraph = false;
|
||||
for (index, unit) in document.units.iter().enumerate() {
|
||||
for (position, item) in unit.items.iter().enumerate() {
|
||||
if position == 0
|
||||
&& document.par_skip > 0
|
||||
&& previous_paragraph
|
||||
&& matches!(item, VerticalItem::Paragraph(_))
|
||||
{
|
||||
if position == 0 && previous_paragraph && matches!(item, VerticalItem::Paragraph(_)) {
|
||||
nodes.push(VerticalNode::Glue(VerticalGlue::new(
|
||||
document.par_skip,
|
||||
0,
|
||||
@@ -2043,13 +2039,6 @@ impl Engine {
|
||||
if starts.is_empty() || document.output_routine.is_some() {
|
||||
return false;
|
||||
}
|
||||
if document.units.iter().any(|unit| {
|
||||
unit.items
|
||||
.iter()
|
||||
.any(|item| matches!(item, VerticalItem::Insertion(_)))
|
||||
}) {
|
||||
return false;
|
||||
}
|
||||
let Some((nodes, owners, node_items)) = document_nodes(document) else {
|
||||
return false;
|
||||
};
|
||||
@@ -2074,6 +2063,14 @@ impl Engine {
|
||||
.rposition(|start| *start <= first_node)
|
||||
.unwrap_or(0);
|
||||
let start_node = starts[page_index];
|
||||
if nodes[..start_node]
|
||||
.iter()
|
||||
.any(|node| matches!(node, VerticalNode::Insertion { .. }))
|
||||
{
|
||||
// Insertion material raised before the replay start may still be
|
||||
// held over; without its state a suffix rebuild would drop it.
|
||||
return false;
|
||||
}
|
||||
let fragments = Self::paged_builder(document).build_from(&nodes, start_node);
|
||||
let rebuilt = Self::paged_pages(document, &owners, &node_items, &fragments);
|
||||
let previous = std::mem::take(&mut self.layout.pages);
|
||||
@@ -5908,6 +5905,29 @@ mod tests {
|
||||
assert!(Engine::layout_paged(&document).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraphs_break_pages_without_par_skip() {
|
||||
let style = ParagraphStyle {
|
||||
line_width: 100 * 65_536,
|
||||
line_height: 12 * 65_536,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let units = [1_u64, 2, 3]
|
||||
.into_iter()
|
||||
.map(|id| {
|
||||
Unit::paragraph_with_style_and_face(
|
||||
id,
|
||||
"alpha",
|
||||
style.clone(),
|
||||
ParagraphFont::Roman,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let document = Document::new(20 * 65_536, units);
|
||||
let engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert_eq!(engine.pages().len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_edit_relayouts_and_reports_changes() {
|
||||
let style = ParagraphStyle {
|
||||
@@ -5937,6 +5957,77 @@ mod tests {
|
||||
assert_eq!(engine.recomputed_pages(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_edit_replays_when_insertions_start_later() {
|
||||
let style = ParagraphStyle {
|
||||
line_width: 100 * 65_536,
|
||||
line_height: 12 * 65_536,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let paragraph = |id, text: &str| {
|
||||
Unit::paragraph_with_style_and_face(id, text, style.clone(), ParagraphFont::Roman)
|
||||
};
|
||||
let mut document = Document::new(
|
||||
20 * 65_536,
|
||||
vec![
|
||||
paragraph(1, "alpha"),
|
||||
paragraph(2, "beta"),
|
||||
paragraph(3, "gamma"),
|
||||
paragraph(4, "delta"),
|
||||
Unit::insertion(
|
||||
5,
|
||||
0,
|
||||
5 * 65_536,
|
||||
vec![VerticalItem::Rule {
|
||||
width: 0,
|
||||
height: 5 * 65_536,
|
||||
}],
|
||||
),
|
||||
],
|
||||
);
|
||||
document.par_skip = 2 * 65_536;
|
||||
let mut engine = Engine::layout_paged(&document).expect("paged");
|
||||
assert_eq!(engine.pages().len(), 4);
|
||||
let first = engine.pages()[0].hash;
|
||||
engine.edit(&document, 3, "epsilon");
|
||||
assert_eq!(engine.pages()[0].hash, first);
|
||||
assert!(engine.recomputed_pages() < 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_edit_rebuilds_when_insertions_precede_the_edit() {
|
||||
let style = ParagraphStyle {
|
||||
line_width: 100 * 65_536,
|
||||
line_height: 12 * 65_536,
|
||||
..ParagraphStyle::default()
|
||||
};
|
||||
let paragraph = |id, text: &str| {
|
||||
Unit::paragraph_with_style_and_face(id, text, style.clone(), ParagraphFont::Roman)
|
||||
};
|
||||
let mut document = Document::new(
|
||||
20 * 65_536,
|
||||
vec![
|
||||
Unit::insertion(
|
||||
1,
|
||||
0,
|
||||
5 * 65_536,
|
||||
vec![VerticalItem::Rule {
|
||||
width: 0,
|
||||
height: 5 * 65_536,
|
||||
}],
|
||||
),
|
||||
paragraph(2, "alpha"),
|
||||
paragraph(3, "beta"),
|
||||
paragraph(4, "gamma"),
|
||||
],
|
||||
);
|
||||
document.par_skip = 2 * 65_536;
|
||||
let mut engine = Engine::layout_paged(&document).expect("paged");
|
||||
let total = engine.pages().len();
|
||||
engine.edit(&document, 4, "delta");
|
||||
assert_eq!(engine.recomputed_pages(), total);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_edit_keeps_untouched_pages() {
|
||||
let style = ParagraphStyle {
|
||||
|
||||
Reference in new issue
Block a user