fix(ui): a click during a background Free Transform commit runs when it lands (#9974)

New Layer while a dropped image was in Free Transform started the commit,
which runs in the background for large images, and was then refused, so
the click was lost. A click now waits for the commit and runs when it
lands. Scripts are still refused, since they need an answer now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DuBearteandClaude Opus 5.5 committed 2026-10-30 14:38:38 -04:00
1 parent b1cfff9d30
commit 39aff2ea02
5 files changed
+29 -8

No files matched your search

+1
View File
@@ -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,
+6 -1
View File
@@ -63,7 +63,12 @@ impl PhotocraftApp {
self.session.precheck(id, &params).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() });
+2
View File
@@ -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<u64>,
/// The session copy, if any, need not track the OS clipboard. An older OS signature is kept
@@ -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
@@ -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");