mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 06:39:10 +00:00
Pen: test that choosing the Pen again inside a compound path selects the compound path
Choosing the Pen again while it draws a path inside a compound path sends only select.set for the compound path, as Escape and Enter do: the path stays open, no undo step is added and the next click starts a new path. Ending a path outside any compound path sends no selection change.
This commit is contained in:
@@ -610,6 +610,58 @@ fn choosing_the_pen_again_ends_the_path() {
|
||||
assert_eq!(t.cursor(&cx, Point::new(300.0, 410.0), Mods::default()), Cursor::Pen);
|
||||
}
|
||||
|
||||
/// Choosing the Pen again while it draws a path inside a compound path ends that path as Escape
|
||||
/// and Enter do: the compound path is selected, the path is not closed, no undo step is added,
|
||||
/// and the next click starts a new path. Ending a path outside any compound path sends no
|
||||
/// selection change.
|
||||
#[test]
|
||||
fn choosing_the_pen_again_selects_the_compound_parent_of_the_path_being_drawn() {
|
||||
let (mut d, _) = doc_with_rect();
|
||||
let l = d.layers[0].id;
|
||||
let (a, b, compound) = (d.alloc_id(), d.alloc_id(), d.alloc_id());
|
||||
let open = |x: f64| {
|
||||
vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&[Point::new(x, 300.0), Point::new(x + 100.0, 300.0)], false))
|
||||
};
|
||||
let path = |id, x| std::sync::Arc::new(vectorcraft_doc::Node::path(id, open(x), vectorcraft_doc::Appearance::default_art()));
|
||||
let mut node = vectorcraft_doc::Node::new(
|
||||
compound,
|
||||
NodeKind::Compound { children: vec![path(a, 10.0), path(b, 300.0)], rule: vectorcraft_geom::FillRule::NonZero },
|
||||
);
|
||||
node.appearance = vectorcraft_doc::Appearance::default_art().into();
|
||||
d.insert(Some(l), 1, node).unwrap();
|
||||
let p = paint();
|
||||
// The member path alone is the selection while the Pen draws it.
|
||||
let mut s = Selection::default();
|
||||
s.set([a]);
|
||||
let inside = cx(&d, &s, &p);
|
||||
// The selection once the engine ran `select.set`: the compound path.
|
||||
let mut sc = Selection::default();
|
||||
sc.set([compound]);
|
||||
let after = cx(&d, &sc, &p);
|
||||
let select_compound = vec![Action::Exec("select.set".into(), json!({"ids": [compound.0]}))];
|
||||
for key in [None, Some(ToolKey::Escape), Some(ToolKey::Enter)] {
|
||||
let mut t = PenTool { drawing: true, path: Some(a), subpath: Some(0), ..PenTool::default() };
|
||||
assert_eq!(t.cursor(&inside, Point::new(250.0, 450.0), Mods::default()), Cursor::PenDrawing, "{key:?}");
|
||||
let acts = match key {
|
||||
Some(k) => t.key(&inside, k, Mods::default()),
|
||||
None => t.chosen_again(&inside),
|
||||
};
|
||||
assert_eq!(acts, select_compound, "{key:?}: only the selection changes, with no close and no undo step");
|
||||
assert!(!t.busy() && t.active(&after).is_none(), "{key:?}: the path is done");
|
||||
assert_eq!(t.cursor(&after, Point::new(250.0, 450.0), Mods::default()), Cursor::Pen, "{key:?}");
|
||||
let next = click(&mut t, &after, 250.0, 450.0, Mods::default());
|
||||
assert!(
|
||||
matches!(next.as_slice(), [Action::Begin(_), Action::Preview(c, _)] if c == "path.create"),
|
||||
"{key:?}: the next click starts a new path: {next:?}"
|
||||
);
|
||||
}
|
||||
let (d, id, s) = drawing(vectorcraft_geom::SubPath::polyline(&[Point::new(100.0, 300.0), Point::new(200.0, 300.0)], false));
|
||||
let plain = cx(&d, &s, &p);
|
||||
let mut t = PenTool { drawing: true, path: Some(id), subpath: Some(0), ..PenTool::default() };
|
||||
assert!(t.chosen_again(&plain).is_empty());
|
||||
assert!(!t.busy() && t.active(&plain).is_none());
|
||||
}
|
||||
|
||||
/// #501: a press on the first anchor closes the path, however far the drag then goes: the
|
||||
/// closing preview leaves the path closed (so not one the pen extends), and each move still
|
||||
/// previews the close with the incoming handle mirroring the pointer (Alt keeps the outgoing one
|
||||
|
||||
Reference in New Issue
Block a user