From 531f44d471eb875203443f8f2503a5f9ced04846 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:01:03 +0100 Subject: [PATCH 1/2] WIP: Crop: picking another tool turns the view upright after a turned crop (#16330) From 04fcc98b2aa1b1da7783826182a57d250226c558 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 23:09:47 +0100 Subject: [PATCH 2/2] Crop: picking another tool turns the view upright after a turned crop (#16330) Leaving the Crop tool commits a drawn frame through CropTool::leave, but the host only turned the view upright for a discard. A default-mode crop that turned the view left it turned at the crop's angle after the commit. The host now turns that document's view upright after the commit leaving the tool makes, accepted or refused, as Enter's does. Classic Mode never turns the view and is unchanged. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/crop_mode_tests.rs | 16 ++++++++++++++++ crates/ui-egui/src/tools/crop_ui.rs | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) 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.