Selection: a press on members picked with Group Selection drags only them

With objects inside a group selected (with Group Selection, for example),
a Selection tool press on one of them selected the whole outer group, so
a drag moved the group instead of the selected members, and the pointer
showed the arrow instead of the move pointer. A press on selected art
under the pointer now keeps the selection: the pointer shows the move
pointer, the drag moves the selected objects, and the anchor or edge
grabbed for snapping is taken from the selected art. A press on a member
that is not selected, or that has only some anchors selected, still
selects the outermost group.

Part of #8047
This commit is contained in:
dotCooCoo
2026-11-15 23:59:05 -08:00
parent ed6f22a84c
commit 05feb87685
2 changed files with 71 additions and 7 deletions
+26 -7
View File
@@ -684,12 +684,16 @@ impl SelectionTool {
return None;
}
let reach = cx.tol(HOVER_REACH);
let under = hit_test(cx.doc, p, cx.selection_hit_options()).map(|h| h.top_object(cx.isolation));
let hit = hit_test(cx.doc, p, cx.selection_hit_options());
let under = hit.as_ref().map(|h| h.top_object(cx.isolation));
let nearest = |points: &mut dyn Iterator<Item = Point>| {
points.filter(|q| q.distance(p) <= reach).min_by(|a, b| a.distance(p).total_cmp(&b.distance(p)))
};
// A press on an unselected object selects it alone: the selected ones stay behind.
let selected = if under.is_none_or(|u| cx.selection.contains(u)) { &cx.selection.objects[..] } else { &[] };
// A press on an unselected object selects it alone: the selected ones stay behind. A press
// on selected art inside it keeps the selection, and that art is the object grabbed.
let kept = hit.as_ref().zip(under).and_then(|(h, u)| selected_under(cx, h, u));
let under = kept.or(under);
let selected = if hit.is_none() || kept.is_some() { &cx.selection.objects[..] } else { &[] };
with_object_bounds(cx, |bounds| {
under.into_iter().chain(selected.iter().copied()).find_map(|id| {
let n = cx.doc.node(id)?;
@@ -999,10 +1003,12 @@ impl Tool for SelectionTool {
let (mut deselect, mut key, mut exclude) = (None, None, None);
if m.shift {
(deselect, exclude) = shift_press(cx, &h, top, &mut out);
} else if !cx.selection.contains(top) {
} else if let Some(picked) = selected_under(cx, &h, top) {
if (cx.selection.objects.len() > 1 || !cx.selection.guides.is_empty()) && !m.cmd && !m.alt {
key = Some(picked);
}
} else {
out.push(Action::Exec("select.set".into(), json!({ "ids": [top.0] })));
} else if (cx.selection.objects.len() > 1 || !cx.selection.guides.is_empty()) && !m.cmd && !m.alt {
key = Some(top);
}
// Grabbed by no anchor or centre, a press on a path's stroke or beside its
// edge holds the path there, and that point of it snaps (#3701).
@@ -1311,7 +1317,7 @@ impl Tool for SelectionTool {
return Cursor::Move;
}
if let Some(h) = hit_test(cx.doc, p, cx.selection_hit_options()) {
if cx.selection.contains(h.top_object(cx.isolation)) || m.alt {
if selected_under(cx, &h, h.top_object(cx.isolation)).is_some() || m.alt {
return Cursor::Move;
}
return Cursor::Arrow;
@@ -1328,6 +1334,19 @@ fn object_behind(cx: &ToolContext, p: Point) -> Option<NodeId> {
stack.get(next).or(stack.first()).copied()
}
/// The selected object a press on `h` lands on: `top` when it is selected, else the outermost
/// object selected whole between it and the art under the pointer, such as members of a group
/// picked with Group Selection. A press there keeps the selection and a drag moves it (#8047). A
/// member with only some anchors or segments selected does not count: the press selects `top`.
fn selected_under(cx: &ToolContext, h: &Hit, top: NodeId) -> Option<NodeId> {
if cx.selection.contains(top) {
return Some(top);
}
let whole = |id: NodeId| cx.selection.contains(id) && cx.selection.partial(id).is_none() && !cx.selection.segments.contains_key(&id);
let below = h.ancestry.iter().position(|id| *id == top).map_or(&[][..], |i| h.ancestry.get(i..).unwrap_or_default());
below.iter().copied().chain(std::iter::once(h.leaf)).find(|id| whole(*id))
}
/// A Shift-press on `top` (hit by `h`): a Shift-click takes a selected object out of the selection
/// when it is released, and a Shift-drag moves the selection, constrained. On an object of the
/// Global Edit that is highlighted, the release leaves that object out of the edit instead, and a
+45
View File
@@ -2665,3 +2665,48 @@ fn outline_view_marquees_measure_a_clip_group_by_its_plain_clipping_path() {
assert_eq!(marquee(true), vec![Action::Exec("select.set".into(), json!({"ids": [g.0]}))]);
assert_eq!(marquee(false), vec![Action::Exec("select.set".into(), json!({"ids": []}))]);
}
/// Objects selected inside a group (with Group Selection, say) stay selected when the Selection
/// tool presses on one of them: the press shows the move pointer and a drag moves only them, not
/// the group around them. A press on a member that is not selected still selects the whole group.
#[test]
fn a_press_on_a_selected_member_of_a_group_moves_the_selected_members() {
use vectorcraft_doc::{Appearance, Document, Node};
use vectorcraft_geom::shapes;
let mut d = Document::new(500.0, 500.0);
let l = d.layers[0].id;
let (outer, inner, a, b, c) = (d.alloc_id(), d.alloc_id(), d.alloc_id(), d.alloc_id(), d.alloc_id());
let path = |id: NodeId, x: f64| Node::path(id, shapes::rectangle(Rect::new(x, 100.0, x + 50.0, 150.0)), Appearance::default_art());
d.insert(Some(l), 0, Node::group(outer, vec![])).unwrap();
d.insert(Some(outer), 0, Node::group(inner, vec![])).unwrap();
d.insert(Some(inner), 0, path(a, 100.0)).unwrap();
d.insert(Some(inner), 1, path(b, 200.0)).unwrap();
d.insert(Some(outer), 1, path(c, 300.0)).unwrap();
let p = paint();
let is_select = |out: &[Action]| out.iter().any(|a| matches!(a, Action::Exec(id, _) if id.starts_with("select.")));
for picked in [vec![a], vec![a, b], vec![inner]] {
let mut s = Selection::default();
s.set(picked.iter().copied());
let c = cx(&d, &s, &p);
let mut t = SelectionTool::default();
assert_eq!(t.cursor(&c, Point::new(125.0, 125.0), Mods::default()), Cursor::Move, "{picked:?}");
let down = t.pointer(&c, &ev(PointerKind::Down, 125.0, 125.0));
assert!(!is_select(&down), "{picked:?}: {down:?}");
let drag = t.pointer(&c, &ev(PointerKind::Drag, 145.0, 125.0));
assert!(drag.iter().any(|a| matches!(a, Action::Preview(c, _) if c == "object.transform")), "{picked:?}: {drag:?}");
}
// A member that is not selected: the press selects the outermost group.
let mut s = Selection::default();
s.set([a]);
let c = cx(&d, &s, &p);
let down = SelectionTool::default().pointer(&c, &ev(PointerKind::Down, 325.0, 125.0));
assert_eq!(down, vec![Action::Exec("select.set".into(), json!({"ids": [outer.0]}))]);
// A member with only some anchors selected (a Direct Selection marquee) is not selected whole:
// the press selects the outermost group, as before.
let mut s = Selection::default();
s.set([a]);
s.anchors.insert(a, [(0, 0)].into_iter().collect());
let c = cx(&d, &s, &p);
let down = SelectionTool::default().pointer(&c, &ev(PointerKind::Down, 125.0, 125.0));
assert_eq!(down, vec![Action::Exec("select.set".into(), json!({"ids": [outer.0]}))]);
}