From 1326394a1cf644f2bcb9961c073e200a759958c3 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 25 Oct 2026 03:17:26 +0100 Subject: [PATCH 1/3] Match Rotation leaves a pending crop's turn out (#9308) In the Crop tool's default mode the active view's camera carries the crop's turn (View::rotation = -crop_angle). Window > Arrange > Match Rotation and Match All copied that turn into every other view and floating window, which stayed turned after the crop was committed. While the crop drives the camera, the view's own rotation is 0 (picking the tool straightened it), so that is what gets copied, and the active view keeps its crop camera. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/crop_mode.rs | 31 +++++++++++++++++++++++++++++++ crates/ui-egui/src/view_cmds.rs | 16 ++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/crop_mode.rs b/crates/ui-egui/src/crop_mode.rs index 36bc4d659a..a7ddd3b7de 100644 --- a/crates/ui-egui/src/crop_mode.rs +++ b/crates/ui-egui/src/crop_mode.rs @@ -745,6 +745,37 @@ mod tests { assert!(out[0].1 == out[1].1, "same pixels"); } + /// #9308: the default mode's camera turn is the crop's, not a view rotation, so Match Rotation + /// and Match All copy 0 to the other views and leave the active view showing the box upright. + #[test] + fn match_rotation_leaves_a_pending_crops_turn_out() { + let ctx = egui::Context::default(); + for id in ["window.arrange.matchRotation", "window.arrange.matchAll"] { + let mut app = app(); + app.run("file.new", json!({"width": 300, "height": 150})).unwrap(); + app.sync_views(); + assert!(app.session.set_active(0)); + app.sync_views(); + let v = &mut app.ui.views[0]; + (v.zoom, v.center, v.fit_pending, v.rotation) = (1.0, [100.0, 50.0], false, 0.0); + app.ui.views[1].rotation = 15.0; + let view = app.ui.views[1].clone(); + app.ui.windows.push(crate::state::DocWindow { id: 7, document: 1, view, open: true, position: None }); + with_frame(&mut app); + screen_drag(&mut app, &[pos2(450.0, 300.0), pos2(440.0, 320.0), pos2(370.0, 380.0)], NONE); + assert!((view_rotation(&app) - 90.0).abs() < 0.01, "{id}: the view turned with the frame"); + let r = crate::menus::invoke(&mut app, &ctx, id, json!({})).unwrap(); + assert_eq!(r["rotation"], 0.0, "{id}: {r}"); + assert_eq!(app.ui.views[1].rotation, 0.0, "{id}: the other document's view"); + assert_eq!(app.ui.windows[0].view.rotation, 0.0, "{id}: the floating window"); + assert!((view_rotation(&app) - 90.0).abs() < 0.01, "{id}: the crop still drives its own view"); + crate::canvas::commit_crop(&mut app); + app.ui.tool = Tool::Brush; + assert_eq!(view_rotation(&app), 0.0, "{id}: after ↵"); + assert_eq!(app.ui.views[1].rotation, 0.0, "{id}: the other view isn't left turned"); + } + } + #[test] fn picking_the_crop_tool_turns_a_rotated_view_upright() { let mut app = app(); diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs index 9fdc456569..12ca38bed1 100644 --- a/crates/ui-egui/src/view_cmds.rs +++ b/crates/ui-egui/src/view_cmds.rs @@ -889,7 +889,11 @@ fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result // Each view stays within its own document's zoom range (a view not drawn yet has no // `doc_size`, so the size comes from the document). let sizes: Vec<[u32; 2]> = app.session.documents().iter().map(|d| [d.doc.size.width, d.doc.size.height]).collect(); - let apply = |v: &mut crate::state::View, doc: usize| { + // A default-mode crop turns the active view's camera; that turn is the crop's, not the + // view's own rotation (which picking the Crop tool made 0), so it isn't copied (#9308). + let crop = crate::crop_mode::turns_view(app); + let rotation = if crop { 0.0 } else { src.rotation }; + let apply = |v: &mut crate::state::View, doc: usize, cropped: bool| { if zoom { v.zoom = crate::zoom_levels::clamp(src.zoom, sizes.get(doc).copied().unwrap_or(v.doc_size)); v.request_zoom_animation(animated_zoom); @@ -897,14 +901,14 @@ fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result if loc { v.center = src.center; } - if rot { - v.rotation = src.rotation; + if rot && !cropped { + v.rotation = rotation; } v.fit_pending = false; }; - app.ui.views.iter_mut().enumerate().for_each(|(d, v)| apply(v, d)); - app.ui.windows.iter_mut().for_each(|w| apply(&mut w.view, w.document)); - Ok(json!({"zoom": src.zoom, "center": src.center, "rotation": src.rotation})) + app.ui.views.iter_mut().enumerate().for_each(|(d, v)| apply(v, d, crop && d == i)); + app.ui.windows.iter_mut().for_each(|w| apply(&mut w.view, w.document, false)); + Ok(json!({"zoom": src.zoom, "center": src.center, "rotation": rotation})) } _ => Err(format!("unknown arrangement {k}")), } From fda46b391df63c06fc327dc6417686897c48fe56 Mon Sep 17 00:00:00 2001 From: David Mann Date: Thu, 29 Oct 2026 17:36:55 +0100 Subject: [PATCH 2/3] Address CodeRabbit review: Match Zoom and Match Location report the camera's rotation They copy no rotation, so the crop's turn isn't left out of their result; only Match Rotation and Match All report the crop-adjusted value they copy. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/menus/view_cmds/arrange.rs | 3 ++- crates/ui-egui/src/tools/crop_mode/tests.rs | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/menus/view_cmds/arrange.rs b/crates/ui-egui/src/menus/view_cmds/arrange.rs index 3749baeb3c..5992019847 100644 --- a/crates/ui-egui/src/menus/view_cmds/arrange.rs +++ b/crates/ui-egui/src/menus/view_cmds/arrange.rs @@ -119,7 +119,8 @@ pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result Err(format!("unknown arrangement {k}")), } diff --git a/crates/ui-egui/src/tools/crop_mode/tests.rs b/crates/ui-egui/src/tools/crop_mode/tests.rs index 92e70bbe27..0c14d30a7a 100644 --- a/crates/ui-egui/src/tools/crop_mode/tests.rs +++ b/crates/ui-egui/src/tools/crop_mode/tests.rs @@ -489,6 +489,30 @@ fn match_rotation_leaves_a_pending_crops_turn_out() { } } +/// Match Zoom and Match Location copy no rotation, so with a crop turning the active view they +/// report its camera's turn as it is and leave every view's rotation alone (#9308). +#[test] +fn match_zoom_and_location_report_the_turned_camera() { + let ctx = egui::Context::default(); + for id in ["window.arrange.matchZoom", "window.arrange.matchLocation"] { + let mut app = app(); + app.run("file.new", json!({"width": 300, "height": 150})).unwrap(); + app.sync_views(); + assert!(app.session.set_active(0)); + app.sync_views(); + let v = &mut app.ui.views[0]; + (v.zoom, v.center, v.fit_pending, v.rotation) = (1.0, [100.0, 50.0], false, 0.0); + app.ui.views[1].rotation = 15.0; + with_frame(&mut app); + screen_drag(&mut app, &[pos2(450.0, 300.0), pos2(440.0, 320.0), pos2(370.0, 380.0)], NONE); + let turned = view_rotation(&app); + assert!((turned - 90.0).abs() < 0.01, "{id}: the view turned with the frame"); + let r = crate::menus::invoke(&mut app, &ctx, id, json!({})).unwrap(); + assert!((r["rotation"].as_f64().unwrap() - f64::from(turned)).abs() < 0.01, "{id}: {r}"); + assert_eq!(app.ui.views[1].rotation, 15.0, "{id}: the other view keeps its rotation"); + } +} + #[test] fn picking_the_crop_tool_turns_a_rotated_view_upright() { let mut app = app(); From 304a1d6aedcfa10bcf3e271608948401d511fb79 Mon Sep 17 00:00:00 2001 From: David Mann Date: Mon, 2 Nov 2026 16:51:50 +0100 Subject: [PATCH 3/3] Tests: build the crop test's DocWindow with main's new floating and focused fields Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/crop_mode/tests.rs | 2 +- 1 file changed, 1 insertion(+), 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 0c14d30a7a..96e1337764 100644 --- a/crates/ui-egui/src/tools/crop_mode/tests.rs +++ b/crates/ui-egui/src/tools/crop_mode/tests.rs @@ -473,7 +473,7 @@ fn match_rotation_leaves_a_pending_crops_turn_out() { (v.zoom, v.center, v.fit_pending, v.rotation) = (1.0, [100.0, 50.0], false, 0.0); app.ui.views[1].rotation = 15.0; let view = app.ui.views[1].clone(); - app.ui.windows.push(crate::state::DocWindow { id: 7, document: 1, view, open: true, position: None }); + app.ui.windows.push(crate::state::DocWindow { id: 7, document: 1, view, open: true, position: None, floating: false, focused: false }); with_frame(&mut app); screen_drag(&mut app, &[pos2(450.0, 300.0), pos2(440.0, 320.0), pos2(370.0, 380.0)], NONE); assert!((view_rotation(&app) - 90.0).abs() < 0.01, "{id}: the view turned with the frame");