From b052fd591ef27281852e6efa4812238ce70a01e9 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 17 Oct 2026 19:15:25 +0200 Subject: [PATCH] Crop: Straighten is one box Undo step (#7127) The Straighten branch of crop_ui::pointer returned before the press step was recorded and pushed, although it turns the frame and makes it pending. With a crop pending, Undo then undid the document (or skipped a box step). It now records the step like every other frame gesture, through a shared push_press_step. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/crop_straighten.rs | 15 ++++++++++++++ crates/ui-egui/src/crop_ui.rs | 29 +++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/crop_straighten.rs b/crates/ui-egui/src/crop_straighten.rs index 9f8128b80a..d3ea8e4792 100644 --- a/crates/ui-egui/src/crop_straighten.rs +++ b/crates/ui-egui/src/crop_straighten.rs @@ -231,6 +231,21 @@ mod tests { assert_eq!(frame_angle([0.0, 0.0], [f64::INFINITY, 1.0], 1.0), None); } + /// A straighten is one box Undo step (#3145): Undo turns the frame back instead of undoing the + /// document under the pending crop, and Redo turns it again. + #[test] + fn straighten_is_a_box_undo_step() { + let mut app = app(SampleType::U8); + let before = (app.ui.crop_rect, app.ui.crop_angle); + drag(&mut app, &[[0.0, 0.0], [100.0, 17.6]], CMD); + let turned = (app.ui.crop_rect, app.ui.crop_angle); + assert!(turned.1.abs() > 5.0, "{turned:?}"); + assert!(crate::crop_ui::intercept(&mut app, "edit.undo").is_some(), "Undo steps the box"); + assert_eq!((app.ui.crop_rect, app.ui.crop_angle), before); + assert!(crate::crop_ui::intercept(&mut app, "edit.redo").is_some()); + assert_eq!((app.ui.crop_rect, app.ui.crop_angle), turned); + } + #[test] fn the_fitted_frame_is_the_largest_of_its_proportions_inside_the_canvas() { // Upright, the canvas's own proportions fill it. diff --git a/crates/ui-egui/src/crop_ui.rs b/crates/ui-egui/src/crop_ui.rs index f1df63ff14..bffc1b46e2 100644 --- a/crates/ui-egui/src/crop_ui.rs +++ b/crates/ui-egui/src/crop_ui.rs @@ -706,9 +706,17 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool if crate::crop_straighten::pointer(app, ev, mods) { claim(app); // Default mode: the image turns so the line ends up level (the press keeps its point). + // The turn is one box Undo step, like any other frame gesture. match ev { - ToolEvent::Down { .. } => crate::crop_mode::sync(app, Some(p)), - _ => crate::crop_mode::sync_frame(app), + ToolEvent::Down { .. } => { + app.crop.press_step = Some(step_of(app)); + crate::crop_mode::sync(app, Some(p)); + } + ToolEvent::Move { .. } => crate::crop_mode::sync_frame(app), + ToolEvent::Up { .. } => { + crate::crop_mode::sync_frame(app); + push_press_step(app); + } } return true; } @@ -774,18 +782,23 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool } _ => {} } - if let Some(before) = app.crop.press_step.take() - && step_of(app) != before - { - app.crop.undo.push(before); - app.crop.redo.clear(); - } + push_press_step(app); } } crate::crop_mode::sync_frame(app); true } +/// On release: the frame state at the press becomes a box Undo step when the gesture changed it. +fn push_press_step(app: &mut PhotocraftApp) { + if let Some(before) = app.crop.press_step.take() + && step_of(app) != before + { + app.crop.undo.push(before); + app.crop.redo.clear(); + } +} + /// The frame follows the pointer at `p`. fn update(app: &mut PhotocraftApp, p: [f64; 2], mods: Modifiers) { let ratio = preset_ratio(app);