Reveal the current slide when another slide takes its place

The thumbnails pane and the sorter revealed the current slide only when its
index changed, so a delete or an undo that put another slide at the same index
left the pane at an old offset with the current slide out of view. The
current slide is now compared by index and id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 22:41:45 +00:00
co-authored by Claude Opus 5.5
parent bad5045a17
commit 3c267a5cae
2 changed files with 20 additions and 2 deletions
+4 -2
View File
@@ -24,7 +24,9 @@ impl SlideApp {
/// Run a command by id (UI commands here, everything else in the engine). Errors show in the
/// status bar and are returned.
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
let before = self.session.active().map(|d| (d.uid, d.selection.slide));
// The current slide by place and by id: a delete or an undo can put another slide at the same place.
let current = |d: &deckcraft_engine::DocState| (d.uid, d.selection.slide, d.current_slide().map(|slide| slide.id));
let before = self.session.active().map(current);
let r = if is_ui_command(id) {
self.run_ui(id, &params)
} else if id == "file.save" && self.host.files().saves_to_page() && params.get("path").is_none() {
@@ -60,7 +62,7 @@ impl SlideApp {
}
self.drain_requests();
if let Some(d) = self.session.active()
&& before != Some((d.uid, d.selection.slide))
&& before != Some(current(d))
{
self.slide_reveal = d.current_slide().map(|slide| slide.id);
}
+16
View File
@@ -292,6 +292,22 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() {
}
}
/// A command that puts another slide in the current place (a delete, its undo) reveals that slide in the thumbnails
/// pane and the sorter, as a move to another place does, so the pane never keeps an offset with the current slide out
/// of view.
#[test]
fn a_new_current_slide_at_the_same_place_is_revealed() {
let mut h = harness(false);
let current = |h: &Harness<'static, Framed>| h.state().session.active().and_then(|d| d.current_slide().map(|slide| slide.id));
h.state_mut().run("slide.go", json!({"index": 0})).unwrap();
h.state_mut().slide_reveal = None;
h.state_mut().run("slide.delete", json!({})).unwrap();
assert_eq!(h.state().session.active().unwrap().selection.slide, 0, "the next slide takes the deleted one's place");
assert_eq!(h.state_mut().slide_reveal.take(), current(&h), "the slide now at the place is revealed");
h.state_mut().run("edit.undo", json!({})).unwrap();
assert_eq!(h.state_mut().slide_reveal.take(), current(&h), "the slide the undo puts back is revealed");
}
/// Every Outline slide has a title field, also a slide whose layout has no title placeholder, and a long body
/// paragraph wraps over several lines of the pane instead of being cut on one.
#[test]