From 2134254ad59d5d7455eecb1c67624199a5b8ba46 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:09:03 +0100 Subject: [PATCH 1/6] Restore crop ratio popup keyboard regression coverage --- crates/ui-egui/tests/it/crop_task_bar.rs | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/ui-egui/tests/it/crop_task_bar.rs b/crates/ui-egui/tests/it/crop_task_bar.rs index 14a391c1db..30bbe4d907 100644 --- a/crates/ui-egui/tests/it/crop_task_bar.rs +++ b/crates/ui-egui/tests/it/crop_task_bar.rs @@ -176,6 +176,41 @@ fn the_bars_preset_dropdown_is_the_options_bars() { assert_eq!(h.get_all_by_value("1 : 1 (Square)").count(), 2, "the options bar shows the same preset"); } +#[test] +fn the_options_bar_ratio_list_takes_escape_and_enter_before_the_crop() { + let mut h = harness(); + control(&mut h, "ui.set", json!({"panels": {"context_task_bar": false}})); + draw_frame(&mut h, [100.0, 50.0], [300.0, 250.0]); + assert!(pending(h.state()), "the drawn square crop is pending"); + let before = frame_rect(&h).expect("the pending frame"); + let size = |h: &Harness| h.state().session.active().map(|s| (s.doc.size.width, s.doc.size.height)); + let square = "1 : 1 (Square)"; + + // Escape dismisses the list. Enter accepts its first row, the selected free Ratio. + // Neither key should reach the pending crop while the list is open (#7386). + for key in [egui::Key::Escape, egui::Key::Enter] { + assert!(!has(&h, square), "the square row is only in the open list"); + let at = h.get_by_value("Ratio").rect().center(); + click_at(&mut h, at); + assert!(has(&h, square), "the options bar ratio list opened"); + h.key_press(key); + h.run_steps(12); + assert!(!has(&h, square), "{key:?} closed the ratio list"); + assert!(pending(h.state()), "{key:?} left the crop pending"); + assert_eq!(frame_rect(&h), Some(before), "{key:?} left the frame alone"); + assert_eq!(size(&h), Some((400, 300)), "{key:?} did not crop the document"); + } + + // A closed dropdown still has focus. Click inside the frame to return focus to the canvas. + let at = h.state().last_canvas_rect.center(); + click_at(&mut h, at); + assert_eq!(frame_rect(&h), Some(before), "the click only moved focus"); + h.key_press(egui::Key::Enter); + h.run_steps(6); + assert_eq!(size(&h), Some((200, 200)), "Enter on the canvas commits the pending crop"); + assert!(!pending(h.state())); +} + #[test] fn inspect_reports_a_bar_hidden_before_the_next_draw_as_hidden() { let mut h = harness(); From c31a1dbbc9f5bc6e9555bd134fd83a58997baa17 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:18:57 +0100 Subject: [PATCH 2/6] Check that canvas Enter records exactly one Crop edit --- crates/ui-egui/tests/it/crop_task_bar.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/tests/it/crop_task_bar.rs b/crates/ui-egui/tests/it/crop_task_bar.rs index 30bbe4d907..87b35c7773 100644 --- a/crates/ui-egui/tests/it/crop_task_bar.rs +++ b/crates/ui-egui/tests/it/crop_task_bar.rs @@ -184,6 +184,8 @@ fn the_options_bar_ratio_list_takes_escape_and_enter_before_the_crop() { assert!(pending(h.state()), "the drawn square crop is pending"); let before = frame_rect(&h).expect("the pending frame"); let size = |h: &Harness| h.state().session.active().map(|s| (s.doc.size.width, s.doc.size.height)); + let history = |h: &Harness| h.state().session.active().expect("the crop document").history.past_len(); + let steps = history(&h); let square = "1 : 1 (Square)"; // Escape dismisses the list. Enter accepts its first row, the selected free Ratio. @@ -208,7 +210,7 @@ fn the_options_bar_ratio_list_takes_escape_and_enter_before_the_crop() { h.key_press(egui::Key::Enter); h.run_steps(6); assert_eq!(size(&h), Some((200, 200)), "Enter on the canvas commits the pending crop"); - assert!(!pending(h.state())); + assert_eq!(history(&h), steps + 1, "Enter adds one document history step"); } #[test] From 59b1751e2106ff9a2277af6de95041113e8655a2 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:23:42 +0000 Subject: [PATCH 3/6] Pass the live Crop tool through the canvas adapter --- crates/ui-egui/src/canvas/tools/crop.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/tools/crop.rs b/crates/ui-egui/src/canvas/tools/crop.rs index d172d522bb..0d9bc1296e 100644 --- a/crates/ui-egui/src/canvas/tools/crop.rs +++ b/crates/ui-egui/src/canvas/tools/crop.rs @@ -21,7 +21,7 @@ pub(crate) fn show_frame(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: egui: Some(app.canvas_tools.crop.tool.show_frame(ui, rect, &run.input(&ctx))) } -/// Applies what the pass reported to the document and the crop options. -pub(crate) fn finish(app: &mut PhotocraftApp, output: CropOutput) { - crate::crop_ui::finish(app, output); +/// Applies what the pass reported while the live Crop tool is still held by the canvas rig. +pub(crate) fn finish(app: &mut PhotocraftApp, tool: &mut CropTool, output: CropOutput) { + crate::crop_ui::finish(app, tool, output); } From caa4fe860acc25e7c1ec09848592a5b8b8bc2abe Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:23:49 +0100 Subject: [PATCH 4/6] Return crop acceptance to the active tool --- crates/ui-egui/src/tools/crop_ui.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 23828a19c6..89e3336a32 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -65,10 +65,14 @@ pub(crate) fn document(app: &PhotocraftApp) -> Option { Some(CropDocument::new(CropDocKey::new(st.doc.id.0), size, f64::from(st.doc.resolution_dpi)).selection(bounds)) } -/// Maps what a pass of the tool reported to the app. -pub(crate) fn finish(app: &mut PhotocraftApp, output: CropOutput) { +/// Maps what a canvas pass reported and acknowledges the crop on the tool that emitted it. +pub(crate) fn finish(app: &mut PhotocraftApp, tool: &mut CropTool, output: CropOutput) { for event in output.events { - handle_event(app, event); + if let CropEvent::Apply(commit) = event { + tool.applied(apply_commit(app, &commit)); + } else { + handle_event(app, event); + } } } @@ -122,7 +126,11 @@ pub(crate) fn toggle_straighten(app: &mut PhotocraftApp) { /// Runs one event of the tool. True for an `Apply` that cropped the document. pub(super) fn handle_event(app: &mut PhotocraftApp, event: impl Into>) -> bool { match event.into() { - Some(CropEvent::Apply(commit)) => apply_commit(app, &commit), + Some(CropEvent::Apply(commit)) => { + let accepted = apply_commit(app, &commit); + app.canvas_tools.crop.tool.applied(accepted); + accepted + } Some(CropEvent::Discard(key)) => { upright_view(app, key); false @@ -137,7 +145,7 @@ pub(super) fn handle_event(app: &mut PhotocraftApp, event: impl Into bool { let rect = commit.frame.rect; let px = |v: f64| v.round().max(1.0) as u64; @@ -164,13 +172,11 @@ fn apply_commit(app: &mut PhotocraftApp, commit: &CropCommit) -> bool { if let Some(view) = app.session.active_index().and_then(|i| app.ui.views.get_mut(i)) { view.place(craft::ui::canvas::ViewCommands::FitOnScreen); } - app.canvas_tools.crop.tool.applied(true); true } Err(error) => { app.ui.status = error; app.ui.status_error = true; - app.canvas_tools.crop.tool.applied(false); false } } From 6e777b496337a27e4d3a548c64767da93f02a663 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:23:58 +0100 Subject: [PATCH 5/6] Acknowledge the result on the Crop tool that emitted it --- crates/ui-egui/src/canvas/tools/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas/tools/mod.rs b/crates/ui-egui/src/canvas/tools/mod.rs index 8e39edf481..94095c3897 100644 --- a/crates/ui-egui/src/canvas/tools/mod.rs +++ b/crates/ui-egui/src/canvas/tools/mod.rs @@ -670,7 +670,7 @@ fn with_rig( if let Some(tool) = crop_tool { tools.crop.tool = tool; } - crop::finish(app, output); + crop::finish(app, &mut tools.crop.tool, output); } result } From eeb92cef243734833e87700d13073570807a0fd1 Mon Sep 17 00:00:00 2001 From: Mex <44814932+MMexicann@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:24:03 +0100 Subject: [PATCH 6/6] Verify Enter and Done clear pending Crop state --- crates/ui-egui/tests/it/crop_task_bar.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-egui/tests/it/crop_task_bar.rs b/crates/ui-egui/tests/it/crop_task_bar.rs index 87b35c7773..100fb88ee3 100644 --- a/crates/ui-egui/tests/it/crop_task_bar.rs +++ b/crates/ui-egui/tests/it/crop_task_bar.rs @@ -211,6 +211,7 @@ fn the_options_bar_ratio_list_takes_escape_and_enter_before_the_crop() { h.run_steps(6); assert_eq!(size(&h), Some((200, 200)), "Enter on the canvas commits the pending crop"); assert_eq!(history(&h), steps + 1, "Enter adds one document history step"); + assert!(!pending(h.state()), "Enter clears the pending Crop session once the document accepts the crop"); } #[test] @@ -281,6 +282,7 @@ fn cancel_and_done_only_while_a_crop_is_pending() { let at = widget(&h, "Done"); click_at(&mut h, at); assert_eq!(h.state().session.active().map(|s| (s.doc.size.width, s.doc.size.height)), Some((220, 170)), "Done crops"); + assert!(!pending(h.state()), "Done also clears the pending Crop session"); } /// The active document's stored zoom.