From 3c267a5cae618a0e3cd4e5c328a190fe3549cb73 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 22:41:45 +0000 Subject: [PATCH] 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 --- crates/ui-egui/src/app/commands.rs | 6 ++++-- crates/ui-egui/src/sorter/ui_tests.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index c23094b50..b01d57451 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -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 { - 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, ¶ms) } 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); } diff --git a/crates/ui-egui/src/sorter/ui_tests.rs b/crates/ui-egui/src/sorter/ui_tests.rs index b3223f2e8..61beae523 100644 --- a/crates/ui-egui/src/sorter/ui_tests.rs +++ b/crates/ui-egui/src/sorter/ui_tests.rs @@ -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]