From 0d10ff57af3728361680e502b912e3d7092591c2 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 4 Nov 2026 19:51:26 +0100 Subject: [PATCH] Fix-up #9739: Reset under W x H x Resolution leaves nothing to reset From CodeRabbit: with an output-size preset, Reset fits the frame and keeps it a pending crop (so Commit still crops), but Reset stayed enabled for that unchanged frame. Reset now remembers the frame it left; the button is live again once the frame changes. The merge with #11011 also keeps the Selection entry's flag when Reset frames a selection again. New test, which fails without the fix. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/crop_ui.rs | 11 ++++++++++- crates/ui-egui/src/tools/crop_ui/tests.rs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index f815ea262cd..4e5382098e4 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -58,6 +58,9 @@ pub struct CropState { /// while this matches. Keyed by id, not tab index, so closing it never hides the frame of the /// tab that takes its place. dismissed: Option<(photocraft_doc::DocId, u32, u32)>, + /// The pending frame [`reset`] left when a W x H x Resolution preset kept it a crop: Reset + /// stays disabled while the frame is still that one. + reset_to: Option<[f64; 4]>, /// The frame is being edited (pressed since it was made): the canvas shows what lies past it. pub editing: bool, /// The document the pending frame (or gesture) belongs to ([`cancel_stale`], #1918). @@ -541,7 +544,10 @@ fn dismiss_key(app: &PhotocraftApp) -> Option<(photocraft_doc::DocId, u32, u32)> /// The frame was drawn, moved, resized or turned since it was last framed by default, so /// [`reset`] has something to undo. pub fn modified(app: &PhotocraftApp) -> bool { - app.ui.tool == Tool::Crop && app.ui.crop_rect.is_some() && app.crop.drag.is_none() && (!app.crop.default_frame || app.ui.crop_angle != 0.0) + app.ui.tool == Tool::Crop + && app.ui.crop_rect.is_some() + && app.crop.drag.is_none() + && (app.ui.crop_angle != 0.0 || (!app.crop.default_frame && app.ui.crop_rect != app.crop.reset_to)) } /// Reset the crop box (the options bar's Reset): the default frame again, upright, with the @@ -564,6 +570,9 @@ pub fn reset(app: &mut PhotocraftApp) { crate::crop_straighten::reset(app); // As a new default frame is: held to the ratio preset (or output size) picked in the bar. fit_frame(app); + // A W x H x Resolution preset keeps the reset frame a pending crop (`fit_frame`), so remember + // it: Reset has nothing more to do until it changes. + app.crop.reset_to = app.ui.crop_rect.filter(|_| !app.crop.default_frame); if step_of(app) != before { app.crop.undo.push(before); app.crop.redo.clear(); diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 00eeaa05960..8281cd7ca46 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -169,6 +169,25 @@ fn reset_holds_the_frame_to_the_ratio_preset() { assert_eq!(app.ui.crop_rect, drawn, "Undo brings the drawn frame back"); } +/// A W x H x Resolution preset keeps the reset frame a pending crop (it sets an output size), so +/// Commit still crops; Reset has nothing more to do on it until the frame changes again. +#[test] +fn reset_under_an_output_size_leaves_nothing_to_reset() { + let mut app = app(SampleType::U8); + ensure_frame(&mut app); + let o = &mut app.ui.tool_options; + o.crop_ratio = crate::crop_size::WHR.into(); + (o.crop_width, o.crop_height, o.crop_resolution) = ("100 px".into(), "100 px".into(), "72".into()); + drag(&mut app, &[[50.0, 20.0], [80.0, 40.0], [120.0, 70.0]], NONE); + assert!(modified(&app)); + reset(&mut app); + assert_eq!(app.ui.crop_rect, Some([50.0, 0.0, 150.0, 100.0])); + assert!(pending(&app), "the output size is still a crop to commit"); + assert!(!modified(&app), "and Reset has nothing more to do"); + drag(&mut app, &[[60.0, 10.0], [90.0, 40.0]], NONE); + assert!(modified(&app), "a new frame can be reset again"); +} + /// #9730: the Crop tool's options bar has a Reset button beside Cancel and Commit, live once /// the frame was changed. #[test]