Merge pull request #2427

With AutoCraft's conflict resolution 3f67bded.
This commit is contained in:
autocraft-bot[bot]
2026-12-04 14:48:40 +00:00
+18
View File
@@ -262,6 +262,13 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
return Err(bad("slide.delete", "no such slide"));
}
s.edit(|doc, sel| {
// Count only slides that are in the deck, each once: an id that names no slide, or a
// repeat, deletes nothing and must not be reported as deleted.
let mut seen = HashSet::new();
let ids: Vec<SlideId> = ids.iter().copied().filter(|id| doc.slide_index(*id).is_some() && seen.insert(*id)).collect();
if ids.is_empty() {
return Err(bad("slide.delete", "no such slide"));
}
let first = ids.iter().filter_map(|id| doc.slide_index(*id)).min().unwrap_or(0);
doc.slides.retain(|x| !ids.contains(&x.id));
for sec in &mut doc.sections {
@@ -987,6 +994,17 @@ mod tests {
assert_eq!(selected(&s), (0, vec![ids[2]]));
}
#[test]
fn delete_reports_only_slides_it_deleted() {
let (mut s, ids) = deck(3);
assert!(s.execute("slide.delete", &json!({"ids": [999_999]})).is_err(), "an id that names no slide deletes nothing");
assert_eq!(order(&s), ids);
let r = s.execute("slide.delete", &json!({"ids": [ids[1], ids[1], 999_999]})).expect("delete");
assert_eq!(order(&s), [ids[0], ids[2]]);
assert_eq!(r["deleted"], 1, "{r}");
assert_eq!(r["remaining"], 2, "{r}");
}
#[test]
fn removing_a_section_with_its_slides_prunes_them_from_custom_shows() {
let (mut s, ids) = deck(4);