From bc8934569df87d0c2abbae648bc381a29941611c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 00:39:31 -0800 Subject: [PATCH] Batch: Escape in the Play, Destination and File Name lists keeps the earlier choice The Batch dialog's lists wrote the row the arrow keys highlighted into the dialog's fields. Escape closed the list but kept that row, and OK then ran the batch with it. The lists now bind to the fields, so Escape restores the earlier choice and only a committed choice applies, as New Action and Action Options do since #9730. --- crates/ui-egui/src/dialogs/action_batch.rs | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/action_batch.rs b/crates/ui-egui/src/dialogs/action_batch.rs index 4b2b79a02d..6e29fc182f 100644 --- a/crates/ui-egui/src/dialogs/action_batch.rs +++ b/crates/ui-egui/src/dialogs/action_batch.rs @@ -307,9 +307,7 @@ impl ActionDialog for BatchDialog { /// A row that picks one of `entries` for `value`. fn select_row(ui: &mut Ui, name: &str, value: &mut T, entries: &[Entry]) { Field::new(label(name)).show(ui, |ui, _| { - if let Some(picked) = Select::new(label(name), Bind::given(*value), entries).show(ui).value().copied() { - *value = picked; - } + Select::new(label(name), Bind::bound(value), entries).show(ui); }); } @@ -417,10 +415,13 @@ impl StackDialog for BatchDialog { #[cfg(test)] mod tests { use craft::automation::actions::{Action, ActionStep}; + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; use vectorcraft_engine::Session; use super::*; use crate::dialogs::actions::pump; + use crate::tests::panel_harness::Panel; /// An app with one set holding `steps` as the action "Draw", and a window to show dialogs in. fn app_with(steps: Vec) -> VectorcraftApp { @@ -498,6 +499,42 @@ mod tests { assert!(!app.session.replaying()); } + #[test] + fn canceled_choices_keep_the_batch_source_destination_and_file_name() { + let mut app = app_with(vec![ActionStep::new("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20}))]); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.run("dataset.new", json!({"name": "a"})).unwrap(); + let mut panel = Panel::new(app, crate::tests::picks::dialogs); + open(&mut panel.app(), 0, 0).unwrap(); + set_fields(&panel.app(), &[("source", json!("datasets"))]); + panel.frame(); + let fields = |panel: &Panel| panel.app().dialogs().unwrap().with(|host| host.get::().unwrap().fields().clone()); + let is_open = |panel: &Panel| panel.app().dialogs().unwrap().with(|host| host.is_open::()); + let original = fields(&panel); + for (name, key) in [("Play", Key::ArrowUp), ("Destination", Key::ArrowUp), ("File Name", Key::ArrowDown)] { + panel.click_role(name, Role::COMBO_BOX); + panel.key(key, Modifiers::NONE); + assert_ne!(fields(&panel), original, "the popup previews {name}"); + panel.key(Key::Escape, Modifiers::NONE); + panel.frame(); + assert!(is_open(&panel), "Escape closes only the {name} popup"); + assert_eq!(fields(&panel), original, "Escape restores {name}"); + } + panel.click_role("Destination", Role::COMBO_BOX); + panel.key(Key::Home, Modifiers::NONE); + panel.key(Key::Enter, Modifiers::NONE); + panel.frame(); + let chosen = fields(&panel); + assert_eq!((chosen.source, chosen.destination), (BatchSource::DataSets, BatchDestination::None)); + panel.click("OK"); + panel.frame(); + panel.frame(); + assert!(!is_open(&panel)); + let app = panel.app(); + assert_eq!(app.session.active().unwrap().doc.layers[0].children().unwrap().len(), 1); + assert!(!app.session.replaying()); + } + #[test] fn data_set_naming_params_follow_dialog_choice() { let mut fields = BatchFields::default();