fix(path): Shift locks a Direct Selection anchor drag to 45° (#5475) (#5498)

Dragging selected anchors with the Direct Selection tool ignored Shift,
so lengthening a slanted bar also nudged it vertically. As in Photoshop,
Shift now locks the anchor move to multiples of 45° from the press, in
the live preview and in the committed path.moveAnchors. It works whether
Shift is held from the press or added during the drag; Shift at the
press still toggles the anchor's selection as before.

Reuses stroke_constraint::snap45 (the Gradient tool's Shift lock).

Fixes #5475

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Brandon Thomas <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-14 22:46:41 -04:00
1 parent 3887d8f738
commit 7efebfa050
2 files changed
+30 -2

No files matched your search

+8 -2
View File
@@ -94,6 +94,11 @@ pub enum Edit {
}
impl Edit {
/// The drag's end with ⇧ held: moving anchors locks to multiples of 45°, as in Photoshop (#5475).
fn constrain(&self, start: [f64; 2], p: [f64; 2], shift: bool) -> [f64; 2] {
if shift && matches!(self, Edit::Anchors(_)) { crate::stroke_constraint::snap45(start, p) } else { p }
}
/// The edit for a drag from `start` to `end`, as a command and its params (without target).
fn command(&self, start: [f64; 2], end: [f64; 2]) -> (&'static str, Value) {
let d = [end[0] - start[0], end[1] - start[1]];
@@ -238,7 +243,7 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
let ds = &mut app.ui.direct_selection;
match &mut ds.drag {
Some(Drag::Edit { base, edit, start, end, preview, .. }) => {
*end = [x, y];
*end = edit.constrain(*start, [x, y], mods.shift);
*preview = edit.preview(base, *start, *end);
}
Some(Drag::Marquee { end, .. }) => *end = [x, y],
@@ -248,7 +253,8 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
}
ToolEvent::Up { x, y } => match app.ui.direct_selection.drag.take() {
Some(Drag::Edit { target, base, edit, start, .. }) => {
release(app, target, &base, &edit, start, [x, y]);
let end = edit.constrain(start, [x, y], mods.shift);
release(app, target, &base, &edit, start, end);
app.ui.direct_selection.coalesce = None;
true
}
+22
View File
@@ -326,6 +326,28 @@ fn arrow_keys_nudge_the_selected_anchors() {
assert_eq!(work(&app), before);
}
/// #5475: ⇧ during an anchor drag locks it to 45°, whether it's held from the press or added later.
#[test]
fn shift_locks_an_anchor_drag_to_45_degrees() {
let mut app = app(Tool::DirectSelection);
with_path(&mut app);
tool_event(&mut app, ToolEvent::Down { x: 40.0, y: 40.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(&mut app, ToolEvent::Move { x: 70.0, y: 44.0, pressure: 1.0 }, Modifiers::SHIFT);
let Some(Drag::Edit { preview: Some(p), .. }) = &app.ui.direct_selection.drag else { panic!("dragging") };
assert_eq!(p.subpaths[0].knots[0].anchor, Point::new(70.0, 40.0), "the preview is locked too");
tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 47.0 }, Modifiers::SHIFT);
assert_eq!(anchor(&app, 0), Point::new(100.0, 40.0));
// Diagonal, and without ⇧ the drag stays free.
// (⇧ at the press would deselect the anchor, so it comes once the drag is under way.)
tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 40.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(&mut app, ToolEvent::Up { x: 131.0, y: 69.0 }, Modifiers::SHIFT);
let a = anchor(&app, 0);
assert!((a.x - 130.0).abs() < 1e-9 && (a.y - 70.0).abs() < 1e-9, "{a:?}");
drag(&mut app, [130.0, 70.0], [140.0, 73.0], Modifiers::NONE);
assert_eq!(anchor(&app, 0), Point::new(140.0, 73.0));
}
#[test]
fn the_curvature_pen_drags_an_anchor_of_the_active_path_without_a_modifier() {
// As in Photoshop: with no path being drawn, pressing an anchor and dragging moves it.