Add slides from an outline to the section of the slide they follow

Found while testing crates/engine/src/cmd/slide.rs:~393 (from_outline), crates/format/src/lib.rs:225 (add_outline_slides)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-18 12:18:49 +00:00
co-authored by Claude Haiku 5.5
parent 22db9261f9
commit 45eeb7c819
2 changed files with 29 additions and 0 deletions
+11
View File
@@ -627,6 +627,17 @@ fn from_outline(s: &mut Session, p: &Value) -> Result<Value> {
for (k, sl) in new.into_iter().enumerate() {
doc.slides.insert(at + k, sl);
}
// Join the section of the slide before, as slide.new does.
let ids: Vec<SlideId> = doc.slides.iter().skip(at).take(n).map(|x| x.id).collect();
let prev = at.checked_sub(1).and_then(|i| doc.slides.get(i)).map(|x| x.id);
let section = prev.and_then(|p| doc.section_of(p));
if let Some(sec) = section.and_then(|si| doc.sections.get_mut(si)) {
let pos = prev.and_then(|p| sec.slides.iter().position(|x| *x == p)).map(|k| k + 1).unwrap_or(sec.slides.len());
let pos = pos.min(sec.slides.len());
sec.slides.splice(pos..pos, ids);
} else if let Some(first) = doc.sections.first_mut() {
first.slides.splice(0..0, ids);
}
Ok(json!({"slides": n}))
})
}