Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Fix View › Snap off still snapping via smart guides (storytold/photocraft#5782).

nrq6993-a11yc71f951b903c
diff --git a/crates/ui-egui/src/snap_ui.rs b/crates/ui-egui/src/snap_ui.rs
index 56fecd01e..b0cb95e2f 100644
--- a/crates/ui-egui/src/snap_ui.rs
+++ b/crates/ui-egui/src/snap_ui.rs
@@ -39,7 +39,7 @@ pub struct ActiveSnap {
pub gesture: Gesture,
pub start: [f64; 2],
pub targets: SnapTargets,
- /// Layer alignments only (smart guides), used when View › Snap is off.
+ /// Layer alignments only (smart guides), when View › Snap and Smart Guides are on.
pub smart: SnapTargets,
pub disabled: bool,
}
@@ -228,7 +228,8 @@ fn begin(app: &mut PhotocraftApp, p: [f64; 2], mods: egui::Modifiers) {
// A moving selection never snaps back to where it started.
targets = targets.filtered(|k| k != SnapKind::Selection);
}
- let smart = if matches!(gesture, Gesture::Move { .. }) && smart_on(app) { build(app, &exclude, true) } else { SnapTargets::default() };
+ let smart =
+ if snap_on(app) && matches!(gesture, Gesture::Move { .. }) && smart_on(app) { build(app, &exclude, true) } else { SnapTargets::default() };
app.prefs_rt.snap = Some(ActiveSnap { gesture, start: p, targets, smart, disabled: false });
}
@@ -571,6 +572,19 @@ mod tests {
}
}
+ #[test]
+ fn view_snap_off_blocks_smart_guide_snapping() {
+ let mut app = app_with_box();
+ app.ui.tool = Tool::Move;
+ app.ui.view.show.smart_guides = true;
+ app.ui.extras.snap = false;
+ app.ui.tool_options.move_auto_select = false;
+ let m = egui::Modifiers::NONE;
+ crate::canvas::tool_event(&mut app, ToolEvent::Down { x: 60.0, y: 60.0, pressure: 1.0 }, m);
+ crate::canvas::tool_event(&mut app, ToolEvent::Up { x: 323.0, y: 100.0 }, m);
+ assert_eq!(mover_bounds(&app).x0, 303, "View › Snap off must not snap via smart guides");
+ }
+
#[test]
fn ctrl_or_snap_off_disables_snapping() {
let mut app = app_with_box();