diff --git a/crates/engine-core/src/cmd/actions_cmds.rs b/crates/engine-core/src/cmd/actions_cmds.rs index a64ce4009a..6ddc1951f3 100644 --- a/crates/engine-core/src/cmd/actions_cmds.rs +++ b/crates/engine-core/src/cmd/actions_cmds.rs @@ -159,7 +159,7 @@ pub fn playback_params(s: &Session, id: &str, p: &Value) -> Result { object.remove("__atnCustom"); } if id == "edit.contentAwareFill" { - crate::atn_cmds::caf_remembered(&mut p, s.prefs()); + crate::atn_cmds::caf_remembered(&mut p, s.prefs())?; } if id == "layer.setProps" && let Some(target) = p.get("_actionLayer") diff --git a/crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs b/crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs index 73eee2cb9d..72f63118f7 100644 --- a/crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs +++ b/crates/engine-core/src/cmd/atn_cmds/steps_content_aware.rs @@ -3,6 +3,7 @@ use super::descriptors::{desc, enm, jstr}; use super::fields::{Mapped, step}; use super::tables::lookup_back; use super::{D, Descriptor, Map, Value}; +use crate::EngineError; const CMD: &str = "edit.contentAwareFill"; const SOURCE: &str = "_atnCafDescriptor"; @@ -99,10 +100,12 @@ fn descriptor(p: &Value) -> Option { /// Resolve an empty recorded step: the remembered settings fill what the step doesn't name, and /// before any were remembered it writes to a new layer. Playing never changes what is remembered. -pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) { - let Some(object) = p.as_object_mut() else { return }; +/// Remembered Custom sampling is refused: its area is painted in the workspace, which keeps none +/// (Custom reopens empty), and the step must not sample another area instead. +pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) -> Result<(), EngineError> { + let Some(object) = p.as_object_mut() else { return Ok(()) }; if object.remove(REMEMBERED).and_then(|v| v.as_bool()) != Some(true) { - return; + return Ok(()); } let saved = prefs.dialogs.get(CAF_WORKSPACE_PREFS); for (param, flag) in PARAMS.iter().map(|param| (*param, matches!(*param, "sampleAllLayers" | "scale" | "mirror"))) { @@ -113,6 +116,11 @@ pub(crate) fn caf_remembered(p: &mut Value, prefs: &crate::prefs::Preferences) { } } object.entry("output").or_insert_with(|| "new".into()); + if object.get("sampling").and_then(Value::as_str) == Some("custom") && !["area", "channel", "samplingStrokes"].iter().any(|key| object.contains_key(*key)) { + let msg = "this step plays with the remembered settings, and their Custom sampling area isn't remembered: fill once with Auto or Rectangular sampling in Content-Aware Fill, then play it again"; + return Err(EngineError::BadParams { cmd: CMD.into(), msg: msg.into() }); + } + Ok(()) } /// Import the verified seven-field form, retaining noncanonical wire data for an unchanged save. diff --git a/crates/ui-egui/src/dialogs/caf_ui/tests.rs b/crates/ui-egui/src/dialogs/caf_ui/tests.rs index c9b5c009af..21f108c52b 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/tests.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/tests.rs @@ -376,6 +376,27 @@ fn settings_closed_without_a_fill_are_not_carried_forward() { assert_eq!(play_empty_recorded_step(&mut restarted), 1, "New Layer: no fill has run"); } +/// After a confirmed Custom fill an empty recorded step stops and says why, instead of filling from another area: the +/// workspace remembers Custom but not its painted area (Custom reopens empty), so the step has none (#14254). +#[test] +fn an_empty_recorded_step_after_a_custom_fill_stops_and_says_why() { + let mut app = app_with_selection(); + open(&mut app).unwrap(); + ui(&mut app, json!({"sampling": "custom", "output": "current"})).unwrap(); + ui(&mut app, json!({"stroke": {"points": [[20.0, 120.0], [60.0, 120.0]], "size": 8}})).unwrap(); + ui(&mut app, json!({"commit": true})).unwrap(); + close_all(&mut app); + let remembered = app.session.prefs().dialogs.get(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS).cloned().unwrap(); + assert_eq!(remembered["sampling"], "custom", "the confirmed fill remembers Custom: {remembered}"); + let revision = app.session.active().unwrap().revision; + let result = play_empty_step(&mut app); + assert_eq!(result["ran"], 0, "{result}"); + let error = result["failed"]["error"].as_str().unwrap_or_default(); + assert!(error.contains("Custom sampling area isn't remembered"), "{result}"); + assert_eq!(app.session.active().unwrap().revision, revision, "the document is unchanged"); + assert_eq!(app.session.prefs().dialogs.get(photocraft_engine::atn_cmds::CAF_WORKSPACE_PREFS), Some(&remembered), "playing remembers nothing"); +} + /// A new app over the saved preferences `prefs`, moved as startup does. fn restart(prefs: photocraft_engine::prefs::Preferences) -> Box { let mut restarted = app_with_selection(); @@ -386,6 +407,14 @@ fn restart(prefs: photocraft_engine::prefs::Preferences) -> Box { /// Plays an action of one empty recorded Content-Aware Fill step and returns how many layers it added. fn play_empty_recorded_step(app: &mut PhotocraftApp) -> usize { + let layers = app.session.active().unwrap().doc.layers.len(); + let result = play_empty_step(app); + assert_eq!(result["ran"], 1, "{result}"); + app.session.active().unwrap().doc.layers.len() - layers +} + +/// Plays an action of one empty recorded Content-Aware Fill step and returns what `actions.play` answers. +fn play_empty_step(app: &mut PhotocraftApp) -> Value { use craft_psd::atn::{AtnAction, AtnEvent, AtnFile, AtnItem}; use craft_psd::descriptor::{Descriptor, UnicodeString}; let item = AtnItem { @@ -401,10 +430,7 @@ fn play_empty_recorded_step(app: &mut PhotocraftApp) -> usize { }; let imported = photocraft_engine::atn_cmds::import(&craft_psd::atn::write(&file).unwrap()).unwrap(); app.session.actions_mut().list.push(imported.actions.into_iter().next().unwrap()).unwrap(); - let layers = app.session.active().unwrap().doc.layers.len(); - let result = app.session.execute("actions.play", json!({"action": 0})).unwrap(); - assert_eq!(result["ran"], 1, "{result}"); - app.session.active().unwrap().doc.layers.len() - layers + app.session.execute("actions.play", json!({"action": 0})).unwrap() } /// The engine's sampling area over the plan's rectangle (what the fill samples) and its fill area. diff --git a/docs/atn.md b/docs/atn.md index ba6b48e302..87a3de3701 100644 --- a/docs/atn.md +++ b/docs/atn.md @@ -430,7 +430,9 @@ step with dialogs on (#14254); the enumeration type IDs are explicit in An empty descriptor (no keys) plays with the settings the fill workspace remembers (`prefs.dialogs["edit.contentAwareFill.workspace"]`), New Layer before any are remembered; it imports as `{"_atnCafRemembered": true}`, which `playback_params` resolves, and saves back -empty. Playing a step never changes what is remembered. +empty. Playing a step never changes what is remembered. When the remembered sampling is Custom, +the step stops with a message instead of filling: the workspace doesn't remember the painted +Custom area (Custom reopens empty), and the step must not sample another area instead. Descriptor types, source identity and key order survive save while its native settings are unchanged. Editing a supported setting exports the new values in canonical form instead of