Merge pull request #8715 from dotCooCoo/fix/history-trim-keeps-the-cleared-brush-source

History: trimming to the memory budget after Clear History keeps the History Brush source
This commit is contained in:
aiongg authored and GitHub committed 2026-10-29 19:23:03 -04:00
commit c5352f204e
2 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -632,7 +632,7 @@ impl History {
continue;
}
total = total.saturating_add(tile_bytes(&s.doc, &mut seen));
if total > self.max_bytes && keep >= 1 {
if total > self.max_bytes && (keep >= 1 || source == Some(undo.len() - 1)) {
break;
}
keep += 1;
+22
View File
@@ -222,6 +222,28 @@ fn byte_budget_keeps_the_brush_source_of_the_cleared_states() {
assert!(Arc::ptr_eq(&h.row_doc(0, &cur).unwrap(), &source), "the History Brush paints from the same state");
}
/// When the History Brush's source is the newest past state, it is the state the byte budget
/// always keeps, and no older state is kept beside it.
#[test]
fn byte_budget_counts_a_newest_brush_source_as_the_kept_state() {
let mut h = History::new(50);
let mut cur = Arc::new(base());
for i in 0..5 {
edit(&mut h, &mut cur, &format!("paint {i}"), |d| {
let id = d.layers[0].id;
d.layer_mut(id).unwrap().surface_mut().unwrap().write_pixel(1, 1, &[i as f32 / 8.0, 0.0, 0.0, 1.0]);
});
}
assert!(h.set_brush_source(4));
let source = h.state(4).unwrap();
h.max_bytes = 1;
assert_eq!(h.trim(&cur), 4);
assert_counter(&h, &cur);
assert_eq!(h.past_len(), 1);
assert_eq!(h.brush_source(), Some(0));
assert!(Arc::ptr_eq(&h.row_doc(0, &cur).unwrap(), &source));
}
#[test]
fn new_edit_clears_redo() {
let mut h = History::default();