diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 5672b91f0b..328288f7eb 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -161,6 +161,7 @@ impl PhotocraftApp { wide_angle: None, dialog_edits: Default::default(), pending_after_prompt: None, + after_transform_commit: None, tone_hist: None, doc_hist: None, doc_hist_preview: None, diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index 5645693e4b..f71991635e 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -63,7 +63,12 @@ impl PhotocraftApp { self.session.precheck(id, ¶ms).map_err(|e| e.to_string())?; transform_tool::commit(self); if transform_tool::committing(self).is_some() { - return Err(tl!("Free Transform is still being applied; try again when it has finished.").into()); + if self.automation_input { + return Err(tl!("Free Transform is still being applied; try again when it has finished.").into()); + } + // A click stays a click: it runs when the commit lands (#9974). + self.after_transform_commit = Some((id.to_string(), params)); + return Ok(Value::Null); } if self.ui.transform.is_some() { return Err(if self.ui.status.is_empty() { tl!("The transform couldn't be applied.").into() } else { self.ui.status.clone() }); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 11967c496d..d45704eedd 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -575,6 +575,8 @@ pub struct PhotocraftApp { /// The filter a "Rasterize?" prompt answered for, run after the dialog closes, where the /// egui context is available again (rasterize_prompt). pub(crate) pending_after_prompt: Option<(String, serde_json::Value)>, + /// A command clicked while Free Transform commits in the background, run when it lands. + pub(crate) after_transform_commit: Option<(String, serde_json::Value)>, /// Last mirrored or imported OS image; this can predate the current internal copy. os_clip_sig: Option, /// The session copy, if any, need not track the OS clipboard. An older OS signature is kept diff --git a/crates/ui-egui/src/tools/transform_tool/commit.rs b/crates/ui-egui/src/tools/transform_tool/commit.rs index 8a26d852f2..4777ac9469 100644 --- a/crates/ui-egui/src/tools/transform_tool/commit.rs +++ b/crates/ui-egui/src/tools/transform_tool/commit.rs @@ -122,6 +122,7 @@ pub fn on_job_event(app: &mut PhotocraftApp, e: &JobEvent) { if committing(app) != Some(e.id) { return; } + let after = app.after_transform_commit.take(); let (Some(t), Some(mut pv)) = (app.ui.transform.take(), app.transform_preview.take()) else { return }; // A refused commit (a result over the pixel budget, #3773) keeps the box open, as inline, // unless picking another tool or layer started it: then the box ends, as Esc would. @@ -133,7 +134,16 @@ pub fn on_job_event(app: &mut PhotocraftApp, e: &JobEvent) { } return; } - finish(app, Some(pv.doc.id), LayerId(t.layer), t.made, matches!(e.outcome, JobOutcome::Done(_))); + let document = pv.doc.id; + let landed = matches!(e.outcome, JobOutcome::Done(_)); + finish(app, Some(document), LayerId(t.layer), t.made, landed); + // Not in another tab, which the click wasn't meant for. + if let Some((id, params)) = after.filter(|_| landed && app.session.active().is_some_and(|st| st.doc.id == document)) + && let Err(e) = app.run(&id, params) + { + app.ui.status = e; + app.ui.status_error = true; + } } /// A commit the engine refused (a result over the pixel budget, #3773): the box stays open as it diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index 2546c14941..42d011dbb6 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -612,20 +612,23 @@ fn another_tool_or_layer_applies_a_transform_committed_in_the_background() { } /// #5667: New Layer while a dropped file is in Free Transform applies the transform first. When -/// the commit runs in the background the command is refused until it has landed, then runs: the -/// place (which takes the move into its step) and the new layer each stay their own step, in -/// that order. +/// the commit runs in the background a click waits for it to land, then runs (#9974): the place +/// (which takes the move into its step) and the new layer each stay their own step, in that +/// order. A script is refused instead, as it needs an answer now. #[test] fn new_layer_applies_the_open_transform() { + let (mut script, ..) = moved_place(); + script.automation_input = true; + let err = script.run("layer.new.layer", json!({})).unwrap_err(); + assert!(err.contains("Free Transform is still being applied"), "a script is refused while the commit runs: {err}"); + let (mut app, placed, frame, steps) = moved_place(); let layers = app.session.active().unwrap().doc.layers.len(); - let err = app.run("layer.new.layer", json!({})).unwrap_err(); - assert!(err.contains("Free Transform is still being applied"), "refused while the commit runs: {err}"); + app.run("layer.new.layer", json!({})).unwrap(); assert_eq!(app.session.active().unwrap().doc.layers.len(), layers, "no layer yet"); land_jobs(&mut app); assert!(app.ui.transform.is_none() && app.transform_preview.is_none(), "the box ended"); assert_eq!(frame_of(&app, placed), Some(frame.translate(8, 0)), "applied as it showed, not the original"); - app.run("layer.new.layer", json!({})).unwrap(); let st = app.session.active().unwrap(); assert_eq!(st.doc.layers.len(), layers + 1); assert_eq!(st.history.past_len(), steps + 2, "the place with its move, then New Layer");