From 16209810d957543a7e7c0d88d58e54630eb78181 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 27 Nov 2026 18:05:09 +0000 Subject: [PATCH] Fix track app-r2-4 causes: natural-height selection pane and preset grids, slide.selectSlides keeps the range anchor, one preview tick a frame, icon text from the framework's Inter, tests query by the port's roles and frame-safe counters Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/slide.rs | 6 +++-- crates/ui-egui/src/app.rs | 3 ++- crates/ui-egui/src/control.rs | 5 +++-- .../src/dialogs/size_position_tests.rs | 2 +- crates/ui-egui/src/huge_deck_tests.rs | 22 +++++++++++-------- crates/ui-egui/src/icons.rs | 2 +- crates/ui-egui/src/icons/geometry.rs | 12 +++++----- crates/ui-egui/src/panels/preset_grid.rs | 1 + crates/ui-egui/src/panels/selpane.rs | 1 + crates/ui-egui/src/panels/smartart_tests.rs | 10 ++++----- crates/ui-egui/src/ribbon/states.rs | 3 +++ crates/ui-egui/src/sorter.rs | 7 ++++-- crates/ui-egui/src/sorter/ui_tests.rs | 4 ++-- 13 files changed, 48 insertions(+), 30 deletions(-) diff --git a/crates/engine/src/cmd/slide.rs b/crates/engine/src/cmd/slide.rs index 1bc3911fd..597bba178 100644 --- a/crates/engine/src/cmd/slide.rs +++ b/crates/engine/src/cmd/slide.rs @@ -38,7 +38,7 @@ pub fn specs() -> Vec { cmd!(noundo "slide.first", "First Slide", [], Some("Home"), "{}", has_slide, first), cmd!(noundo "slide.last", "Last Slide", [], Some("End"), "{}", has_slide, last), cmd!(noundo "slide.selectRange", "Select Slide Range", [], None, "{to: index, from?: index (default the current slide), add?: bool (keep the slides already selected)}", has_slide, select_range), - cmd!(noundo "slide.selectSlides", "Select Slides", [], None, "{ids?: [slide id], indices?: [index], add?: bool}", has_slide, select_slides), + cmd!(noundo "slide.selectSlides", "Select Slides", [], None, "{ids?: [slide id], indices?: [index], add?: bool, anchor?: slide id (the range anchor of a grid selection)}", has_slide, select_slides), cmd!("slide.hide", "Hide Slide", ["Slide Show", "Set Up"], None, "{index?, hidden?: bool}", has_slide, hide), cmd!("slide.layout", "Layout", ["Home", "Slides"], None, "{layout: name or kind, index?}", has_slide, set_layout), cmd!("slide.reset", "Reset", ["Home", "Slides"], None, "{index?}", has_slide, reset), @@ -394,6 +394,7 @@ fn last(s: &mut Session, _p: &Value) -> Result { fn select_slides(s: &mut Session, p: &Value) -> Result { let add = bool_or(p, "add", false); + let anchor = p.get("anchor").and_then(Value::as_u64).and_then(|x| u32::try_from(x).ok()).map(SlideId); let ids: Vec = { let st = s.doc()?; let mut v: Vec = p @@ -422,7 +423,8 @@ fn select_slides(s: &mut Session, p: &Value) -> Result { } sel.shapes.clear(); sel.text = None; - sel.range_anchor = None; + let current = doc.slides.get(sel.slide).map(|x| x.id); + sel.range_anchor = anchor.filter(|a| doc.slide_index(*a).is_some()).zip(current); })?; Ok(json!({"selected": s.doc()?.selection.slides})) } diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index bed1d99d2..75c69986b 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -398,7 +398,8 @@ impl SlideApp { self.sync_backstage(); if self.show.is_some() { self.anim_preview = None; - } else if self.tick_anim_preview(self.clock.now()) { + } else if ctx.current_pass_index() == 0 && self.tick_anim_preview(self.clock.now()) { + // One tick a frame: a discarded frame's second pass reads a later wall clock and would draw the preview twice. ctx.request_repaint(); } let show_page = self.show.is_some(); diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index d3f6ab586..d81c442c1 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -989,11 +989,12 @@ mod tests { |_| {}, ); let listener = std::net::TcpListener::bind(("127.0.0.1", 0))?; - let (receiver, listening) = server::serve(listener, "token".into(), WindowHost::of(&harness.ctx))?; + let token = craft::automation::security::generate_token()?; + let (receiver, listening) = server::serve(listener, token.clone(), WindowHost::of(&harness.ctx))?; harness.state_mut().control = Some(ControlChannel::new(receiver)); let addr = listening.addr; let notice = "A notice sent over the socket"; - let client = std::thread::spawn(move || ControlClient::connect(addr, "token").map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice}))); + let client = std::thread::spawn(move || ControlClient::connect(addr, &token).map_err(|e| format!("{e:?}"))?.call("ui.notify", json!({"text": notice}))); let mut frames = 0; while !client.is_finished() && frames < 600 { harness.run_steps(1); diff --git a/crates/ui-egui/src/dialogs/size_position_tests.rs b/crates/ui-egui/src/dialogs/size_position_tests.rs index f88f524f7..4fe325beb 100644 --- a/crates/ui-egui/src/dialogs/size_position_tests.rs +++ b/crates/ui-egui/src/dialogs/size_position_tests.rs @@ -74,7 +74,7 @@ fn lock_aspect_from_the_dialog_scales_height() { h.run_steps(1); h.key_press(egui::Key::Enter); h.run_steps(2); - dialog(&mut h, "ui.dialog.confirm", json!({"dialog": "top"})); + assert!(super::open_keys(&h.ctx).is_empty(), "Enter in the width field is OK"); let after = box_of(h.state(), id); let width = 4.0 * 72.0; assert_eq!(after, (before.0, before.1, width, before.3 * width / before.2, before.4)); diff --git a/crates/ui-egui/src/huge_deck_tests.rs b/crates/ui-egui/src/huge_deck_tests.rs index eac972b21..de1b7e40e 100644 --- a/crates/ui-egui/src/huge_deck_tests.rs +++ b/crates/ui-egui/src/huge_deck_tests.rs @@ -16,14 +16,18 @@ fn harness(n: usize) -> egui_kittest::Harness<'static, SlideApp> { crate::test_harness::harness(s, Services::default()) } -/// A root frame with two uploads and two passes contributes two uploads, not four. +/// Thumbnails rendered since the harness began: each one is a held entry or an evicted one. The store's per-frame +/// `uploads` count is rolled over when a frame ends, so it reads zero between harness steps. +fn renders(h: &egui_kittest::Harness<'_, SlideApp>) -> usize { + let stats = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx); + stats.entries + stats.evicted +} + +/// The thumbnails rendered by `frames` more frames. fn step_uploads(h: &mut egui_kittest::Harness<'_, SlideApp>, frames: usize) -> usize { - let mut uploads = 0; - for _ in 0..frames { - h.run_steps(1); - uploads += crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads; - } - uploads + let before = renders(h); + h.run_steps(frames); + renders(h) - before } /// Outline view of 2000 slides lays out the slides in view (and the current one), not all 2000 @@ -84,7 +88,7 @@ fn the_sorter_of_a_huge_deck_renders_only_the_slides_in_view() { #[test] fn a_settled_thumbnail_pane_renders_nothing_more() { let mut h = harness(800); - let initial = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads; + let initial = renders(&h); let rendered = initial + step_uploads(&mut h, 60); let held = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).entries; // Every thumbnail held was rendered, and the pane did not render many it then threw away: @@ -122,7 +126,7 @@ fn a_settled_thumbnail_pane_renders_nothing_more() { fn a_settled_sorter_renders_nothing_more() { let mut h = harness(800); h.state_mut().ui.view = crate::ViewMode::Sorter; - let initial = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).uploads; + let initial = renders(&h); let rendered = initial + step_uploads(&mut h, 60); let held = crate::thumb_source::thumbnails(&h.ctx).cache().statistics(&h.ctx).entries; assert!(rendered >= held && rendered < held * 2, "{rendered} renders for {held} thumbnails"); diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs index e6dfa6239..0e6a2a9e0 100644 --- a/crates/ui-egui/src/icons.rs +++ b/crates/ui-egui/src/icons.rs @@ -364,7 +364,7 @@ mod tests { fn names_round_trip_and_are_unique() { assert!( geometry::text_face().is_some(), - "icon coverage requires CRAFT_FONTS_DIR to embed a parseable Inter Regular face" + "icon coverage requires the framework's parseable Inter Regular face" ); register(); register(); diff --git a/crates/ui-egui/src/icons/geometry.rs b/crates/ui-egui/src/icons/geometry.rs index e6bbfc882..83214b00a 100644 --- a/crates/ui-egui/src/icons/geometry.rs +++ b/crates/ui-egui/src/icons/geometry.rs @@ -175,12 +175,14 @@ pub(super) fn tf(c: P2, ang: f32, pts: &[P2]) -> Vec { pub(super) fn text_face() -> Option<&'static ttf_parser::Face<'static>> { static FACE: OnceLock>> = OnceLock::new(); FACE.get_or_init(|| { - let face = deckcraft_fonts::CRAFT_FONTS - .iter() - .find(|font| font.family == "Inter" && font.style == "Regular") - .and_then(|font| ttf_parser::Face::parse(font.bytes, 0).ok()); + // The suite's interface face ships with the framework's default faces; its bytes live for the process. + let face = craft::ui::fonts::deflated_default_definitions() + .font_data + .get("Inter-Regular") + .map(|data| &*Box::leak(data.font.to_vec().into_boxed_slice())) + .and_then(|bytes| ttf_parser::Face::parse(bytes, 0).ok()); if face.is_none() { - log::warn!("DeckCraft icon text omitted: embedded Inter Regular is missing or invalid; supply CRAFT_FONTS_DIR"); + log::warn!("DeckCraft icon text omitted: the framework's Inter Regular is missing or invalid"); } face }) diff --git a/crates/ui-egui/src/panels/preset_grid.rs b/crates/ui-egui/src/panels/preset_grid.rs index 661d1a562..dc4d17d81 100644 --- a/crates/ui-egui/src/panels/preset_grid.rs +++ b/crates/ui-egui/src/panels/preset_grid.rs @@ -21,6 +21,7 @@ pub(crate) fn preset_grid 0, "gallery pictures were drawn"); let layout = deckcraft_engine::cmd::smartart::LAYOUTS.iter().find(|(kind, _)| *kind == "verticalBoxList").unwrap(); - h.get_by_role_and_label(egui::accesskit::Role::Button, layout.1).hover(); + h.get_by_role_and_label(egui::accesskit::Role::ListItem, layout.1).hover(); // The tile's rich tip opens after the pointer rests; each harness step advances 1/60 s. h.run_steps(60); let hovered = crate::ribbon::diagram_thumbs::thumbnails(&h.ctx).cache().statistics(&h.ctx); @@ -148,7 +148,7 @@ fn layout_gallery_shows_cached_pictures_and_previews_on_hover() { h.run_steps(60); let settled = crate::ribbon::diagram_thumbs::thumbnails(&h.ctx).cache().statistics(&h.ctx); assert_eq!(settled.entries, hovered.entries, "pictures are cached, not redrawn every frame"); - h.get_by_role_and_label(egui::accesskit::Role::Button, layout.1).click(); + h.get_by_role_and_label(egui::accesskit::Role::ListItem, layout.1).click(); h.run_steps(3); let st = h.state().session.active().unwrap(); assert_eq!(deckcraft_engine::cmd::smartart::selected(st).unwrap().1.kind, layout.0); diff --git a/crates/ui-egui/src/ribbon/states.rs b/crates/ui-egui/src/ribbon/states.rs index 8df131932..1e1de54b3 100644 --- a/crates/ui-egui/src/ribbon/states.rs +++ b/crates/ui-egui/src/ribbon/states.rs @@ -122,6 +122,9 @@ mod tests { ); h.get_by_role_and_label(Role::Tab, "View").click(); h.run_steps(3); + for node in h.query_all_by_role(Role::Button).chain(h.query_all_by_role(Role::CheckBox)) { + eprintln!("DIAG a_toggle_shows_checked_while_the_state_it_changes_holds: {:?} {:?}", node.accesskit_node().role(), node.accesskit_node().label()); + } let off = h.get_by_role_and_label(Role::Button, "Slide Master").accesskit_node().toggled(); assert_eq!(off, Some(Toggled::False)); h.get_by_role_and_label(Role::Button, "Slide Master").click(); diff --git a/crates/ui-egui/src/sorter.rs b/crates/ui-egui/src/sorter.rs index 0cf6b552e..4409470cf 100644 --- a/crates/ui-egui/src/sorter.rs +++ b/crates/ui-egui/src/sorter.rs @@ -92,7 +92,6 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) { let Some(st) = app.session.active() else { return }; let (uid, doc, cur) = (st.uid, st.doc.clone(), st.selection.slide); let lead = doc.slides.get(cur).map(|slide| Key::Slide(slide.id)); - // PLAN: plan error: slide.selectSlides clears range_anchor; shell-w4 must preserve the grid anchor and a deselected lead in its command interface. let anchor = st.selection.range_anchor.map(|(first, _)| Key::Slide(first)).or(lead); let mut selection = Selection::new(st.selection.slides.iter().copied().map(Key::Slide).collect(), lead, anchor); let mut keys = Vec::with_capacity(doc.slides.len()); @@ -253,7 +252,11 @@ fn select_slides(app: &mut SlideApp, doc: &Presentation, selection: &Selection Some(anchor.0), + _ => None, + }; + let _ = app.run("slide.selectSlides", json!({"ids": ids, "add": false, "anchor": anchor})); } fn section_menu(app: &mut SlideApp, ui: &mut Ui, index: usize, opener: &egui::Response, words: &SorterWords) { diff --git a/crates/ui-egui/src/sorter/ui_tests.rs b/crates/ui-egui/src/sorter/ui_tests.rs index 44414ef04..b7345d003 100644 --- a/crates/ui-egui/src/sorter/ui_tests.rs +++ b/crates/ui-egui/src/sorter/ui_tests.rs @@ -280,8 +280,8 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() { h.run_steps(3); let words = craft::ui::runtime::env::Env::of_root(&h.ctx).words::(); let values: Vec<_> = h.query_all_by_role(Role::TextInput).filter_map(|node| node.value()).collect(); - assert!(h.query_by_role_and_label(Role::TextInput, words.slide_title.as_str()).is_some()); - assert!(h.query_by_role_and_label(Role::TextInput, words.slide_text.as_str()).is_some()); + assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_title.as_str()).next().is_some()); + assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_text.as_str()).next().is_some()); for text in included { assert!(values.contains(&text), "title and body belong in the Outline"); }