Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

KEY-CROP-SWAP: X in the crop tool swaps the aspect once (#1866)

G6billee8eed1c7621
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index b9d1874a1..9458c94c6 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -466,6 +466,7 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
app.toast(ctx, e);
}
}
+ let rotate_fires = fire.iter().any(|f| f == "crop.rotateAspect");
for f in fire {
// a slideshow: ←/→ step (a cut)
if app.ui.slideshow.is_some() && matches!(f.as_str(), "library.next" | "library.previous") {
@@ -587,9 +588,12 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
}
continue;
}
- // X is both reject (library) and swap crop aspect (crop tool)
+ // X is both reject (library) and swap crop aspect (crop tool). When both bindings fire,
+ // swap once: twice would put the crop straight back (issue #1866).
if f == "photo.reject" && app.ui.right == crate::state::RightPanel::Crop {
- let _ = app.run("crop.rotateAspect", json!({}));
+ if !rotate_fires {
+ let _ = app.run("crop.rotateAspect", json!({}));
+ }
continue;
}
if f == "crop.rotateAspect" && app.ui.right != crate::state::RightPanel::Crop {
diff --git a/crates/ui-egui/src/tests_crop_tool.rs b/crates/ui-egui/src/tests_crop_tool.rs
index 47b5264e0..75010d1f5 100644
--- a/crates/ui-egui/src/tests_crop_tool.rs
+++ b/crates/ui-egui/src/tests_crop_tool.rs
@@ -62,3 +62,36 @@ fn escape_in_the_angle_field_only_leaves_the_field() {
h.settle(SETTLE);
assert_eq!((h.app.ui.view, h.app.ui.right == RightPanel::Crop), (ViewMode::Detail, false));
}
+
+/// X in the crop tool swaps the crop's orientation once (issue #1866). X is both Reject and Swap
+/// Aspect, and both bindings fired: the crop turned portrait and straight back to landscape.
+#[test]
+fn x_in_the_crop_tool_swaps_the_aspect_once() {
+ let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), Services { png: None, ..Default::default() });
+ let mut h = Headless::new(app, [1400.0, 900.0], 1.0);
+ let landscape =
+ |h: &Headless, id: &lightcraft_catalog::PhotoId| h.app.session.catalog.photo(*id).is_some_and(|p| p.width > p.height && !p.is_edited());
+ let id = h.app.session.visible_cloned().into_iter().find(|id| landscape(&h, id)).unwrap();
+ h.request("engine.execute", json!({"command": "library.select", "params": {"ids": [id.0], "active": id.0}}), T);
+ h.app.ui.view = ViewMode::Detail;
+ h.request("engine.execute", json!({"command": "panel.crop"}), T);
+ let r = h.request("engine.execute", json!({"command": "crop.aspect", "params": {"aspect": [3, 4]}}), T);
+ assert_eq!(r["ok"], true, "{r}");
+ h.settle(SETTLE);
+ assert_eq!(h.app.ui.right, RightPanel::Crop);
+ let crop = |h: &Headless| {
+ let p = h.app.session.catalog.photo(id).unwrap();
+ let r = p.develop.crop.geometry.rect_px(p.width as f64, p.height as f64);
+ (r.width() > r.height(), p.develop.crop.aspect)
+ };
+ assert_eq!(crop(&h), (true, Some((300, 400))), "a 3:4 crop follows the landscape photo");
+ let undo = h.app.session.undo.len();
+ h.request("ui.key", json!({"key": "x"}), T);
+ h.settle(SETTLE);
+ assert_eq!(crop(&h), (false, Some((400, 300))), "X turns the crop portrait");
+ assert_eq!(h.app.session.undo.len(), undo + 1, "one swap, one undo step");
+ assert_eq!(h.app.session.catalog.photo(id).unwrap().flag, lightcraft_catalog::Flag::None, "X doesn't reject while cropping");
+ h.request("ui.key", json!({"key": "x"}), T);
+ h.settle(SETTLE);
+ assert_eq!(crop(&h), (true, Some((300, 400))), "X again turns it back");
+}
diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md
index 95dcd2aef..59aeda0e5 100644
--- a/docs/parity-checklist.md
+++ b/docs/parity-checklist.md
@@ -668,7 +668,7 @@ From `06-shortcuts.md` part 1. Evidence is our binding; conflicts are explained
| KEY-GENAI | Generative toggles / variations — ⌥⇧G, ⌥←/→ | OOS | 🚫 | | |
| KEY-DETECT | Detect objects — ⌥⇧O | P2 | ⬜ | | |
| KEY-CROP-CONSTRAIN | Lock crop aspect — A | P1 | ✅ | `cmd:crop.aspect` (`toggle`, `current`) | A while cropping locks the current shape / unlocks |
-| KEY-CROP-SWAP | Swap crop orientation — X | P0 | ✅ | `cmd:crop.rotateAspect` | |
+| KEY-CROP-SWAP | Swap crop orientation — X | P0 | ✅ | `cmd:crop.rotateAspect` | in the crop tool X swaps once instead of also running Reject's swap, which put the crop straight back (issue #1866) |
| KEY-CROP-OVERLAYORIENT | Crop overlay orientation — ⇧O | P1 | ✅ | `cmd:view.cropOverlayOrientation` | while cropping: O cycles the overlay, ⇧O its orientation |
| KEY-CROP-RESET | Reset crop — ⌥⌘R | P0 | ✅ | `cmd:crop.reset` | |
| KEY-STRAIGHTEN | Straighten while held — ⌘ drag | P1 | ✅ | `cmd:crop.straighten`, `crates/ui-egui/src/panels/detail.rs` (`straighten_overlay`) | ⌘-drag in Crop draws a level line; the crop tool stays active |