diff --git a/crates/ui-egui/src/tools/crop_mode_tests.rs b/crates/ui-egui/src/tools/crop_mode_tests.rs index 9745508aa1..16fc5e45eb 100644 --- a/crates/ui-egui/src/tools/crop_mode_tests.rs +++ b/crates/ui-egui/src/tools/crop_mode_tests.rs @@ -101,3 +101,19 @@ fn a_dropped_crop_turns_its_own_documents_view_upright() { assert!(!crop_ui::pending(&app), "the turned crop is dropped with its document"); assert_eq!(app.ui.views[0].rotation, 0.0, "its own document's view is upright again"); } + +/// Picking another tool commits a turned crop, and the view the crop turned goes upright with it: the turn is in the +/// cropped pixels now, not in the view. +#[test] +fn another_tool_commits_a_turned_crop_and_turns_the_view_upright() { + let mut app = app(); + turn_the_view(&mut app); + assert_ne!(app.ui.views[0].rotation, 0.0, "the view turned with the crop"); + app.ui.tool = Tool::Brush; + frame(&mut app); + frame(&mut app); + let st = app.session.active().unwrap(); + assert_eq!(st.history.undo_label(), Some("Crop"), "leaving the tool commits the turned crop"); + assert_ne!(st.doc.size, Size::new(200, 100)); + assert_eq!(app.ui.views[0].rotation, 0.0, "the view is upright again"); +} diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 89e3336a32..1235377484 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -76,7 +76,8 @@ pub(crate) fn finish(app: &mut PhotocraftApp, tool: &mut CropTool, output: CropO } } -/// Runs once per pass: while another tool is current, a drawn frame is cropped as leaving the tool does. +/// Runs once per pass: while another tool is current, a drawn frame is cropped as leaving the tool does, and the view +/// is upright after it. pub(crate) fn each_pass(app: &mut PhotocraftApp) { if app.ui.tool == Tool::Crop { return; @@ -85,7 +86,13 @@ pub(crate) fn each_pass(app: &mut PhotocraftApp) { let keeps_pending = app.stylus.tool_before_eraser == Some(Tool::Crop); let (settings, units) = (app.ui.tool_options.crop.clone(), units(app)); let event = app.canvas_tools.crop.tool.leave(&settings, &document, &units, keeps_pending); + // The tool drives the view only while it is picked: the view a default-mode crop turned goes upright with the + // commit leaving the tool makes, accepted or refused, as Enter's does (#16330). + let commits = matches!(event, Some(CropEvent::Apply(_))); handle_event(app, event); + if commits { + upright_view(app, document.key); + } } /// The one commit: the menus, the bar, the task bar and the canvas menu call it. True when the document was cropped.