mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Quick Pen: an open end on a selected segment continues its path
A click on an open end of another path that lies on a segment of the selected path now goes on drawing from that end, and the pointer shows that it will. Before, the segment took the press and the click started a new path. An anchor of the selected path still comes first.
This commit is contained in:
1 parent
357133cef1
commit
cb3946fe2f
2 files changed
+31
-3
No files matched your search
@@ -821,6 +821,23 @@ fn a_segment_drag_moves_only_its_ends() {
|
||||
assert_eq!(paths(&s).len(), 1);
|
||||
}
|
||||
|
||||
/// A click on an open end of another path, in front of the selected path, that lies on a segment
|
||||
/// of the selected path goes on drawing from that end.
|
||||
#[test]
|
||||
fn an_open_end_on_a_selected_segment_continues_its_path() {
|
||||
let mut s = session();
|
||||
let id = selected_quick_pen_path(&mut s, (100.0, 300.0), json!([{"x": 300, "y": 300}]));
|
||||
let r = s.execute("shape.line", &json!({"x1": 200, "y1": 200, "x2": 200, "y2": 300})).unwrap();
|
||||
let other = NodeId(r["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
click(&mut s, 200.0, 300.0);
|
||||
click(&mut s, 250.0, 250.0);
|
||||
let all = paths(&s);
|
||||
assert_eq!(all.len(), 2, "no new path");
|
||||
let ends: Vec<Point> = all.iter().find(|(id, _)| *id == other).unwrap().1.subpaths[0].anchors.iter().map(|a| a.p).collect();
|
||||
assert_eq!(ends, [pt(200.0, 200.0), pt(200.0, 300.0), pt(250.0, 250.0)]);
|
||||
}
|
||||
|
||||
/// Escape during a drag puts the anchor back, and the release then changes nothing.
|
||||
#[test]
|
||||
fn escape_takes_back_an_anchor_drag() {
|
||||
|
||||
@@ -449,7 +449,10 @@ impl QuickPenTool {
|
||||
self.press = Some(Press { at: p, dragged: false, begun: true });
|
||||
return vec![Action::Begin("Quick Pen".into()), Action::Preview(COMMAND.into(), self.params(false)), drawn()];
|
||||
}
|
||||
if let Some(grab) = edit::grab_at(cx, p, tol) {
|
||||
// An anchor of a selected path comes first, then an open end, then a selected path's
|
||||
// segment.
|
||||
let grab = edit::grab_at(cx, p, tol);
|
||||
if let Some(grab @ Grab::Anchor { .. }) = grab {
|
||||
self.edit = Some(Edit::new(cx, grab, p, shift));
|
||||
return vec![];
|
||||
}
|
||||
@@ -458,6 +461,10 @@ impl QuickPenTool {
|
||||
{
|
||||
return self.continue_path(cx, id, si, at_first);
|
||||
}
|
||||
if let Some(grab) = grab {
|
||||
self.edit = Some(Edit::new(cx, grab, p, shift));
|
||||
return vec![];
|
||||
}
|
||||
self.start_path(cx, p)
|
||||
}
|
||||
|
||||
@@ -789,10 +796,14 @@ impl Tool for QuickPenTool {
|
||||
if let Some(e) = &self.edit {
|
||||
return if e.began { Cursor::Move } else { edit::cursor(cx, e.grab) };
|
||||
}
|
||||
if let Some(grab) = edit::grab_at(cx, p, tol) {
|
||||
let grab = edit::grab_at(cx, p, tol);
|
||||
if let Some(grab @ Grab::Anchor { .. }) = grab {
|
||||
return edit::cursor(cx, grab);
|
||||
}
|
||||
if open_end_at(cx, p, tol, None).is_some() { Cursor::PenContinue } else { Cursor::Pen }
|
||||
if open_end_at(cx, p, tol, None).is_some() {
|
||||
return Cursor::PenContinue;
|
||||
}
|
||||
grab.map_or(Cursor::Pen, |grab| edit::cursor(cx, grab))
|
||||
}
|
||||
|
||||
fn options(&self) -> Value {
|
||||
|
||||
Reference in new issue
Block a user