From e1e0e010f583d30007d8e9b5111902ee996fb116 Mon Sep 17 00:00:00 2001 From: Zinadin Zidan Date: Sat, 5 Dec 2026 18:49:52 +0600 Subject: [PATCH] Drop the single-slide tick from the thumbnail Hide/Show row Follows up #2725, whose review found the thumbnail slide menu's Hide/Show row borrowing the engine command's checked state. `slide.hide`'s checked state is computed in `crates/ui-egui/src/ribbon/states.rs` from the current slide alone, while the bare command applies to every slide in `selection.slides` (crates/engine/src/cmd/slide.rs:479-498), so a mixed selection led by a hidden slide showed a tick on a row labelled "Hide Slide" and the menu announced the row as checked. The row is now a plain `MenuItem`: it runs `slide.hide` with no params itself and closes the menu with `cx.request_close()`, and keeps the all-hidden label computed over the same target list the engine uses. The change stays inside `slide_menu`; no engine or ribbon state changes. Tests: `panels::thumbs::tests::the_slide_menu_hides_and_shows_every_selected_slide` (a mixed selection reads Hide Slide and one click flips the whole selection in a single undo step, then a second click shows it again) and `panels::thumbs::tests::the_slide_menu_hide_row_carries_no_single_slide_toggle` (the row reports no toggled state and the click does what the label said). Part of #2553 --- crates/ui-egui/src/panels/thumbs.rs | 40 +++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/thumbs.rs b/crates/ui-egui/src/panels/thumbs.rs index b11298748..b2ec727ae 100644 --- a/crates/ui-egui/src/panels/thumbs.rs +++ b/crates/ui-egui/src/panels/thumbs.rs @@ -229,7 +229,7 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res menu = menu.anchor(anchor); } } - let out = menu.show(ui, |ui, _| { + let out = menu.show(ui, |ui, cx| { if !craft::ui::runtime::measure::active(ui.ctx()) && app .session @@ -258,6 +258,8 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res let _ = MenuItem::command(pane).label(tl!("Format Background…")).show(ui); // The row toggles every selected slide, as the ribbon's toggle does, so it reads "Show Slide" only when every // slide it targets is already hidden; a mixed selection hides. The targets are the engine's `slide.hide` ones. + // It stays a plain item: that command's checked state follows the current slide alone, so borrowing it would + // stamp a selection-wide row with one slide's on/off mark, against the label here. let all_hidden = app.session.active().is_some_and(|state| { let sel = &state.selection; let mut targets: Vec = sel.slides.iter().filter_map(|id| state.doc.slide_index(*id)).collect(); @@ -267,7 +269,10 @@ pub(crate) fn slide_menu(ui: &mut Ui, app: &mut SlideApp, key: u64, opener: &Res targets.iter().all(|at| state.doc.slides.get(*at).is_some_and(|slide| slide.hidden)) }); let label = if all_hidden { words.show_slide.clone() } else { words.hide_slide.clone() }; - let _ = MenuItem::command(CommandRef::new("slide.hide")).label(label).show(ui); + if MenuItem::new(label).show(ui).ran { + let _ = app.run("slide.hide", json!({})); + cx.request_close(); + } }); if out.closed.is_some() && requested { app.pane_menu = None; @@ -546,22 +551,47 @@ mod tests { // A half-hidden selection offers to hide, as the engine's all-hidden toggle does. h.state_mut().pane_menu = Some(("thumbs".into(), 0)); h.run_steps(4); - assert!(h.query_by_role_and_label(Role::MenuItemCheckBox, words.show_slide.as_str()).is_none(), "a mixed selection reads Hide Slide"); + assert!(h.query_by_label(words.show_slide.as_str()).is_none(), "a mixed selection reads Hide Slide"); let undo = deck(&h)?.history.undo.len(); - h.get_by_role_and_label(Role::MenuItemCheckBox, words.hide_slide.as_str()).click(); + h.get_by_label(words.hide_slide.as_str()).click(); h.run_steps(3); let flags: Vec = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect(); assert_eq!(flags, [true, true, true, false], "the click hides every selected slide, not only the one it opened on"); assert_eq!(deck(&h)?.history.undo.len(), undo + 1, "hiding a whole selection is one undo step"); h.state_mut().pane_menu = Some(("thumbs".into(), 0)); h.run_steps(4); - h.get_by_role_and_label(Role::MenuItemCheckBox, words.show_slide.as_str()).click(); + h.get_by_label(words.show_slide.as_str()).click(); h.run_steps(3); let flags: Vec = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect(); assert_eq!(flags, [false, false, false, false], "a second click shows the whole selection again"); Ok(()) } + /// The slide menu's Hide/Show row names a selection-wide action, so it carries no on/off mark: the bare command's + /// checked state follows only the current slide, and that would contradict the row whenever a mixed selection is + /// led by a hidden slide. + #[test] + fn the_slide_menu_hide_row_carries_no_single_slide_toggle() -> Result<(), String> { + let words = ThumbWords::english(); + let mut h = editor(slides(4)?, 900.0); + h.state_mut().run("slide.hide", json!({"index": 0, "hidden": true}))?; + // A backward range makes the hidden slide 0 the current one, leading a selection that is only half hidden. + h.state_mut().run("slide.selectRange", json!({"from": 2, "to": 0}))?; + assert_eq!(deck(&h)?.selection.slide, 0, "the range's end is the current slide"); + h.run_steps(3); + h.state_mut().pane_menu = Some(("thumbs".into(), 0)); + h.run_steps(4); + let row = h.get_by_label(words.hide_slide.as_str()); + assert_eq!(row.accesskit_node().toggled(), None, "a selection-wide row shows no current slide's mark"); + let undo = deck(&h)?.history.undo.len(); + row.click(); + h.run_steps(3); + let flags: Vec = deck(&h)?.doc.slides.iter().map(|slide| slide.hidden).collect(); + assert_eq!(flags, [true, true, true, false], "the label it showed is what the click did"); + assert_eq!(deck(&h)?.history.undo.len(), undo + 1, "the whole selection flips in one undo step"); + Ok(()) + } + /// A header counts in the grid's destination, but never in the engine's slide order. #[test] fn slides_move_dest_counts_without_the_moved_slides() -> Result<(), String> {