mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Quick Pen: a first Shift-click selects one anchor; a segment drag moves its ends
A first Shift-click on an anchor of a path selected whole now selects that anchor alone. Before, it selected every other anchor of the path. A drag on a segment now moves only that segment's two ends. Before, when both ends were selected together with other anchors, the drag moved the other anchors too.
This commit is contained in:
1 parent
78d2a634dd
commit
17a1a5543f
3 files changed
+42
-2
No files matched your search
@@ -705,6 +705,33 @@ fn clicks_select_anchors_for_delete() {
|
||||
assert!(!left.contains(&pt(200.0, 100.0)) && !left.contains(&pt(300.0, 100.0)), "{left:?}");
|
||||
}
|
||||
|
||||
/// The first Shift-click on an anchor of a path selected whole selects that anchor alone.
|
||||
#[test]
|
||||
fn a_first_shift_click_selects_the_anchor_alone() {
|
||||
let mut s = session();
|
||||
let id = selected_quick_pen_path(&mut s, (100.0, 100.0), json!([{"x": 200, "y": 100}, {"x": 300, "y": 100}]));
|
||||
assert!(s.doc().unwrap().selection.partial(id).is_none(), "the path is selected whole");
|
||||
shift_click(&mut s, 200.0, 100.0);
|
||||
let picked = s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::<Vec<_>>();
|
||||
assert_eq!(picked, [(0, 1)]);
|
||||
}
|
||||
|
||||
/// A drag on a segment moves its two ends alone, also when they are selected with another anchor.
|
||||
#[test]
|
||||
fn a_segment_drag_moves_only_its_ends() {
|
||||
let mut s = session();
|
||||
let pieces = json!([{"x": 300, "y": 300}, {"x": 300, "y": 400}, {"x": 100, "y": 400}, {"x": 100, "y": 500}]);
|
||||
let id = selected_quick_pen_path(&mut s, (100.0, 300.0), pieces);
|
||||
click(&mut s, 300.0, 300.0);
|
||||
shift_click(&mut s, 300.0, 400.0);
|
||||
shift_click(&mut s, 100.0, 400.0);
|
||||
let picked = s.doc().unwrap().selection.partial(id).cloned().unwrap_or_default().into_iter().collect::<Vec<_>>();
|
||||
assert_eq!(picked, [(0, 1), (0, 2), (0, 3)]);
|
||||
press(&mut s, &[(300.0, 350.0), (320.0, 350.0), (350.0, 350.0)]);
|
||||
assert_eq!(points(&s), [pt(100.0, 300.0), pt(350.0, 300.0), pt(350.0, 400.0), pt(100.0, 400.0), pt(100.0, 500.0)]);
|
||||
assert_eq!(paths(&s).len(), 1);
|
||||
}
|
||||
|
||||
/// Escape during a drag puts the anchor back, and the release then changes nothing.
|
||||
#[test]
|
||||
fn escape_takes_back_an_anchor_drag() {
|
||||
|
||||
@@ -512,7 +512,11 @@ impl QuickPenTool {
|
||||
}
|
||||
match e.grab {
|
||||
Grab::Anchor { id, si, ai, .. } if e.shift => {
|
||||
vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": "toggle"}))]
|
||||
// `select.anchors` toggles from every anchor of a path selected whole on its own,
|
||||
// so the first Shift-click there selects the anchor alone.
|
||||
let whole = cx.selection.anchors.is_empty() && cx.selection.objects.len() <= 1;
|
||||
let mode = if whole { "set" } else { "toggle" };
|
||||
vec![Action::Exec("select.anchors".into(), json!({"id": id.0, "anchors": [[si, ai]], "mode": mode}))]
|
||||
}
|
||||
Grab::Anchor { id, si, ai, end: true, .. } => self.continue_path(cx, id, si, ai == 0),
|
||||
Grab::Anchor { id, si, ai, .. } => {
|
||||
|
||||
@@ -109,7 +109,16 @@ impl Edit {
|
||||
return out;
|
||||
}
|
||||
let Some(picked) = self.grab.anchors(cx) else { return out };
|
||||
let already = cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a)));
|
||||
// A drag on one of several selected anchors moves them all; a drag on a segment moves
|
||||
// its two ends alone.
|
||||
let already = match self.grab {
|
||||
Grab::Anchor { .. } => cx.selection.partial(id).is_some_and(|s| picked.iter().all(|a| s.contains(a))),
|
||||
Grab::Segment { .. } => {
|
||||
cx.selection.objects == [id]
|
||||
&& cx.selection.anchors.len() == 1
|
||||
&& cx.selection.partial(id).is_some_and(|s| s.len() == picked.len() && picked.iter().all(|a| s.contains(a)))
|
||||
}
|
||||
};
|
||||
let moving = if already {
|
||||
cx.selection.clone()
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user