Content-Aware Fill: a refused fill keeps the last remembered settings (#14254)

Apply and OK write the recorded settings to prefs only after the fill runs, so
a refused fill no longer changes what an empty recorded step plays with. The
CAF export test helper now fails when a successful save writes no readable item.
This commit is contained in:
RickiNano committed 2026-11-18 20:26:55 +01:00
1 parent 3ca447202b
commit f398e8798b
3 files changed
+26 -5

No files matched your search

@@ -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<AtnItem> {
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]
@@ -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)
@@ -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<bool>, Vec<bool>) {
let c = app.caf.as_ref().unwrap();