diff --git a/crates/engine/src/cmd/atn_cmds/caf_action_values_tests.rs b/crates/engine/src/cmd/atn_cmds/caf_action_values_tests.rs index 1b4bb5f9d4..9380424ebd 100644 --- a/crates/engine/src/cmd/atn_cmds/caf_action_values_tests.rs +++ b/crates/engine/src/cmd/atn_cmds/caf_action_values_tests.rs @@ -44,12 +44,14 @@ fn load(d: Descriptor) -> Action { loaded.actions.into_iter().next().unwrap() } -/// The item Save Actions writes for one step, or `None` when it cannot write it. +/// The item Save Actions writes for one step, or `None` when it refuses the step. A save that succeeds must +/// write a readable file holding the item. fn exported(p: Value) -> Option { let a = Action::new("A", vec![ActionStep::new(CMD, p)]); let (bytes, skipped) = export("S", &[&a], &[], false).ok()?; assert!(skipped.is_empty()); - atn::parse(&bytes).ok()?.actions.into_iter().next()?.items.into_iter().next() + let saved = atn::parse(&bytes).expect("a successful save writes a readable file"); + Some(saved.actions.into_iter().next().and_then(|a| a.items.into_iter().next()).expect("the saved file holds the step")) } #[test] diff --git a/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs b/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs index 9527bc2453..aec8cd6b52 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs @@ -139,12 +139,15 @@ fn remember(app: &mut PhotocraftApp, command: &FillCommand) { app.session.prefs.edit(|p| p.dialogs.insert(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS.into(), Value::Object(settings))); } -/// Fills with `command` (one history step); the workspace stays as it is. A refusal is reported. +/// Fills with `command` (one history step); the workspace stays as it is. A refusal is reported and keeps the +/// settings of the last fill that ran. pub(super) fn apply(app: &mut PhotocraftApp, command: &FillCommand) -> Result<(), String> { let layer = app.caf.as_ref().ok_or("Content-Aware Fill is not open")?.layer; - remember(app, command); match app.run(CMD, plan_params(command, layer)) { - Ok(_) => Ok(()), + Ok(_) => { + remember(app, command); + Ok(()) + } Err(e) => { report(app, &e); Err(e) diff --git a/crates/ui-egui/src/dialogs/caf_ui/tests.rs b/crates/ui-egui/src/dialogs/caf_ui/tests.rs index 5915e4f2cd..9897c42179 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/tests.rs @@ -274,6 +274,22 @@ fn apply_and_ok_keep_the_settings_for_an_empty_recorded_step() { assert_eq!(saved(&app).unwrap()["output"], "duplicate", "OK remembers too"); } +/// A fill the engine refuses leaves the settings of the last fill that ran for an empty recorded step (#14254). +#[test] +fn a_refused_fill_keeps_the_last_remembered_settings() { + let mut app = app_with_selection(); + let saved = |app: &PhotocraftApp| app.session.prefs().dialogs.get(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS).cloned(); + open(&mut app).unwrap(); + ui(&mut app, json!({"output": "current", "colorAdaptation": "none", "apply": true})).unwrap(); + let remembered = saved(&app).expect("the Apply that ran remembers its settings"); + app.session.execute("layer.setProps", json!({"locks": {"pixels": true}})).unwrap(); + ui(&mut app, json!({"colorAdaptation": "high", "mirror": true})).unwrap(); + assert!(ui(&mut app, json!({"apply": true})).is_err(), "the engine refuses the locked layer"); + assert_eq!(saved(&app), Some(remembered.clone()), "a refused Apply remembers nothing"); + assert!(ui(&mut app, json!({"commit": true})).is_err(), "the engine refuses OK too"); + assert_eq!(saved(&app), Some(remembered), "a refused OK remembers nothing"); +} + /// The engine's sampling area over the plan's rectangle (what the fill samples) and its fill area. fn engine_source(app: &PhotocraftApp) -> (Rect, Vec, Vec) { let c = app.caf.as_ref().unwrap();