mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Direct Selection: hover marks the anchor a press takes across selected groups
The selected paths a hover tries were listed group by group in selection order, while a press tries them topmost first across the document. With two selected groups whose anchors fall within reach, hover marked the back group's anchor and a press took the front one. The list is now sorted in paint order, topmost first, with a Shaper Group's original shapes included.
This commit is contained in:
1 parent
7c50924fcb
commit
3d33094d39
2 files changed
+45
-5
No files matched your search
@@ -641,15 +641,14 @@ pub fn over_selected_part(cx: &ToolContext, p: Point) -> bool {
|
||||
}
|
||||
|
||||
/// The editable paths of the selected objects and inside them (a selected group's members), with
|
||||
/// their control bounds: each selected object's paths topmost first, in selection order. The list
|
||||
/// is made once per document state and selection; a hover measures only the paths whose bounds it
|
||||
/// is near.
|
||||
/// their control bounds, topmost first across the whole document: the order [`hit_anchor`] tries
|
||||
/// them in. The list is made once per document state and selection; a hover measures only the
|
||||
/// paths whose bounds it is near.
|
||||
fn selected_part_boxes(cx: &ToolContext) -> std::sync::Arc<[(NodeId, vectorcraft_geom::Rect)]> {
|
||||
crate::select::selected_part_boxes(cx, || {
|
||||
let editable = cx.doc.editable();
|
||||
let mut v = vec![];
|
||||
for root in cx.selection.objects.iter().filter_map(|&id| cx.doc.node(id)) {
|
||||
let from = v.len();
|
||||
walk_pickable_from(root, &mut |n| {
|
||||
if editable(n.id)
|
||||
&& let Some(b) = editable_path(n).and_then(|pd| pd.control_bounds())
|
||||
@@ -657,8 +656,21 @@ fn selected_part_boxes(cx: &ToolContext) -> std::sync::Arc<[(NodeId, vectorcraft
|
||||
v.push((n.id, b));
|
||||
}
|
||||
});
|
||||
v[from..].reverse();
|
||||
}
|
||||
// The paint order of every node, a Shaper Group's original shapes included (isolation can
|
||||
// select them); the topmost path comes first.
|
||||
fn walk_all(n: &Node, order: &mut std::collections::HashMap<NodeId, usize>) {
|
||||
let i = order.len();
|
||||
order.insert(n.id, i);
|
||||
for c in n.children().into_iter().flatten() {
|
||||
walk_all(c, order);
|
||||
}
|
||||
}
|
||||
let mut order = std::collections::HashMap::new();
|
||||
for l in &cx.doc.layers {
|
||||
walk_all(l, &mut order);
|
||||
}
|
||||
v.sort_by_key(|(id, _)| std::cmp::Reverse(order.get(id).copied()));
|
||||
v.into()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3074,3 +3074,31 @@ fn select_behind_is_measured_once_for_a_point() {
|
||||
assert!(crate::select::selects_behind_at(&c, at));
|
||||
assert_eq!(MEASURED_PARTS.get() - before, 1, "measured for the first ask only");
|
||||
}
|
||||
|
||||
/// With two selected groups whose anchors sit on the same point, the highlighted anchor is the one
|
||||
/// a press takes: the front group's, whatever order the groups were selected in.
|
||||
#[test]
|
||||
fn the_highlighted_anchor_of_two_selected_groups_is_the_one_a_press_takes() {
|
||||
let mut d = vectorcraft_doc::Document::new(500.0, 500.0);
|
||||
let l = d.layers[0].id;
|
||||
let (back_path, back, front_path, front) = (d.alloc_id(), d.alloc_id(), d.alloc_id(), d.alloc_id());
|
||||
let path = |id, x| {
|
||||
std::sync::Arc::new(vectorcraft_doc::Node::path(
|
||||
id,
|
||||
vectorcraft_geom::shapes::rectangle(Rect::new(x, x, x + 100.0, x + 100.0)),
|
||||
vectorcraft_doc::Appearance::default_art(),
|
||||
))
|
||||
};
|
||||
d.insert(Some(l), 0, vectorcraft_doc::Node::group(back, vec![path(back_path, 100.0)])).unwrap();
|
||||
d.insert(Some(l), usize::MAX, vectorcraft_doc::Node::group(front, vec![path(front_path, 100.0)])).unwrap();
|
||||
let p = paint();
|
||||
let corner = Point::new(100.0, 100.0);
|
||||
for order in [[back, front], [front, back]] {
|
||||
let mut s = Selection::default();
|
||||
s.set(order);
|
||||
let c = cx(&d, &s, &p);
|
||||
let pressed = hit_anchor(&c, corner, c.point_tol()).map(|(id, ..)| id);
|
||||
assert_eq!(pressed, Some(front_path), "a press takes the front anchor (selected {order:?})");
|
||||
assert_eq!(hovered_anchor(&c, corner), Some((front_path, corner)), "the front anchor is highlighted (selected {order:?})");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user