diff --git a/crates/ui-egui/src/menus/view_cmds/arrange.rs b/crates/ui-egui/src/menus/view_cmds/arrange.rs index 9cf7a61d80..3b81474605 100644 --- a/crates/ui-egui/src/menus/view_cmds/arrange.rs +++ b/crates/ui-egui/src/menus/view_cmds/arrange.rs @@ -107,7 +107,11 @@ pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result = 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); @@ -115,14 +119,15 @@ 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 c0afceb0d1..cb5041a2fe 100644 --- a/crates/ui-egui/src/tools/crop_mode/tests.rs +++ b/crates/ui-egui/src/tools/crop_mode/tests.rs @@ -458,6 +458,61 @@ fn commit_is_the_same_in_both_modes_and_the_view_stays_upright() { 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, 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"); + 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"); + } +} + +/// 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"); + } +} + /// #9202: switching documents drops a turned pending crop and turns its own document's view /// upright, as Esc would, not only the view of the document switched to. #[test]