PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Crop: Enter during a drag ends the drag (#7055) (#7056)
David Mannbf638a7a228c
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 02fb1b33c..b20f82798 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -6148,6 +6148,8 @@ pub fn commit_crop(app: &mut PhotocraftApp) {crate::crop_ui::cancel_stale(app);// Committing ends the box's own Undo/Redo: from here Edit › Undo reverts the document.crate::crop_ui::clear_history(app);+ // ↵ during a drag ends it: the release must not bring back the old document's frame.+ app.crop.drag = None;let Some(r) = app.ui.crop_rect.take() else { return };// The crop's default mode leaves the view upright (`crop_mode`).crate::crop_mode::upright(app);diff --git a/crates/ui-egui/src/crop_ui.rs b/crates/ui-egui/src/crop_ui.rsindex f1df63ff1..00700ae5c 100644--- a/crates/ui-egui/src/crop_ui.rs+++ b/crates/ui-egui/src/crop_ui.rs@@ -1724,6 +1724,22 @@ mod tests {}}+ #[test]+ fn enter_during_a_drag_ends_the_drag() {+ // ↵ while the frame is still being dragged commits it; the release after must not bring+ // back a frame in the old document's coordinates as a pending crop.+ let mut app = app(SampleType::U8);+ app.ui.crop_rect = Some([20.0, 20.0, 120.0, 70.0]);+ tool_event(&mut app, ToolEvent::Down { x: 50.0, y: 40.0, pressure: 1.0 }, NONE);+ tool_event(&mut app, ToolEvent::Move { x: 60.0, y: 40.0, pressure: 1.0 }, NONE);+ crate::canvas::commit_crop(&mut app);+ tool_event(&mut app, ToolEvent::Up { x: 60.0, y: 40.0 }, NONE);+ ensure_frame(&mut app);+ assert_eq!(app.session.active().unwrap().doc.size, Size::new(100, 50));+ assert_eq!(app.ui.crop_rect, Some([0.0, 0.0, 100.0, 50.0]));+ assert!(!pending(&app));+ }+#[test]fn degenerate_and_bad_input_never_panics() {let mut app = app(SampleType::U8);