Merge pull request #9309 from davidmann4/fix/match-rotation-crop-turn

Match Rotation leaves a pending crop's turn out (#9308)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-06 17:23:58 +01:00
commit fff0db9850
2 files changed
+66 -6

No files matched your search

+11 -6
View File
@@ -107,7 +107,11 @@ pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result<Val
// 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);
@@ -115,14 +119,15 @@ pub(super) fn arrange(app: &mut PhotocraftApp, k: &str, p: &Value) -> Result<Val
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));
// Match Zoom and Match Location copy no rotation: they report the camera's as it is.
Ok(json!({"zoom": src.zoom, "center": src.center, "rotation": if rot { rotation } else { src.rotation }}))
}
_ => Err(format!("unknown arrangement {k}")),
}
@@ -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]