Direct Selection: a locked target does not open its group, and a second Shift-click deselects one anchor

expand_to took in the target without checking that it is editable, so a
locked or hidden object inside a selected group replaced the group with
its contents. It now leaves the selection unchanged for such a target.

select.anchors with mode toggle decided whether a path was selected whole
from the rest of the selection, so after a Shift-click had opened a group,
a Shift-click on an anchor of another path in it selected only that
anchor. A toggle on a group member now decides it from the member's own
selection; paths directly on a layer keep the existing rule.
This commit is contained in:
dotCooCoo committed 2026-11-28 04:34:32 -08:00
1 parent 3e8d293232
commit 65d9ba2469
4 files changed
+31 -6

No files matched your search

+3 -3
View File
@@ -199,8 +199,8 @@ impl Selection {
/// When `id` is also selected itself, it keeps its place in the selection.
///
/// Returns whether the selection changed. It does not change when `id` is not inside a selected
/// object, is inside one that is partly selected (anchors or segments), or is one of a selected
/// Shaper Group's original shapes.
/// object, is inside one that is partly selected (anchors or segments), is one of a selected
/// Shaper Group's original shapes, or is hidden, locked or on a locked artboard itself.
pub fn expand_to(&mut self, doc: &Document, id: NodeId) -> bool {
let Some(chain) = doc.ancestry(id) else { return false };
let Some(top) = chain.iter().position(|a| self.contains(*a)) else { return false };
@@ -217,7 +217,7 @@ impl Selection {
if children.iter().take(originals).any(|c| c.id == pair[1]) {
return false;
}
members.extend(children.iter().skip(originals).map(|c| c.id).filter(|c| *c == id || (*c != pair[1] && editable(*c))));
members.extend(children.iter().skip(originals).map(|c| c.id).filter(|c| editable(*c) && (*c == id || *c != pair[1])));
}
if !members.contains(&id) {
return false;
+8
View File
@@ -109,6 +109,14 @@ fn expand_to_selects_a_member_in_place_of_its_selected_group() {
with_locked.set([k]);
assert!(with_locked.expand_to(&d, last));
assert_eq!(with_locked.objects, [shown, last]);
// A locked or hidden member itself does not open the group.
for target in [locked, hidden] {
let mut s = Selection::default();
s.set([k]);
let before = s.clone();
assert!(!s.expand_to(&d, target), "{target:?}");
assert_eq!(s, before);
}
}
/// A selection with every field set: objects 1 to 6 with 3 listed twice, anchors, segments, a key,
+8 -3
View File
@@ -959,9 +959,14 @@ fn anchors(s: &mut Session, p: &Value) -> Result<Value> {
// A path selected as a whole has every anchor selected: toggle and add start from them all,
// but only when no partial anchor selection is active and only on a single isolated object.
// A toggle on a path inside a selected group selects the path itself in the group's place,
// beside the group's other objects, and starts from all its anchors.
let inside = mode == "toggle" && sel.expand_to(d, id);
let whole = inside || (sel.contains(id) && sel.partial(id).is_none() && sel.anchors.is_empty() && sel.objects.len() <= 1);
// beside the group's other objects, and starts from all its anchors. A toggle on a group
// member that is itself selected whole (as an earlier toggle in the group leaves the other
// members) starts from all its anchors whatever else is selected.
let toggle = mode == "toggle";
let inside = toggle && sel.expand_to(d, id);
let own = sel.contains(id) && sel.partial(id).is_none();
let in_group = || d.ancestry(id).is_some_and(|c| c.len() >= 2 && d.node(c[c.len() - 2]).is_some_and(|n| !n.is_layer()));
let whole = inside || (own && ((sel.anchors.is_empty() && sel.objects.len() <= 1) || (toggle && in_group())));
sel.add(id);
// A segment pick's endpoints aren't selected anchors: start from none of them.
if sel.segments.remove(&id).is_some() {
@@ -112,6 +112,18 @@ fn remove_and_anchor_toggle_open_a_selected_group() {
assert_eq!(sel.objects, [a, b, c]);
assert_eq!(sel.partial(a), Some(&[(0, 0), (0, 2), (0, 3)].into()), "the other anchors of a stay selected");
assert_eq!((sel.partial(b), sel.partial(c)), (None, None), "b and c stay selected whole");
// A second Shift-click, on an anchor of b, deselects only that anchor of b.
s.execute("select.anchors", &json!({"id": b.0, "anchors": [[0, 2]], "mode": "toggle"})).unwrap();
let sel = &s.active().unwrap().selection;
assert_eq!(sel.objects, [a, b, c]);
assert_eq!(sel.partial(a), Some(&[(0, 0), (0, 2), (0, 3)].into()));
assert_eq!(sel.partial(b), Some(&[(0, 0), (0, 1), (0, 3)].into()), "the other anchors of b stay selected");
assert_eq!(sel.partial(c), None);
// An anchor of a path that is not selected joins the selection by itself.
let d = NodeId(s.execute("shape.rectangle", &json!({"x": 60, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
s.execute("select.anchors", &json!({"id": d.0, "anchors": [[0, 1]], "mode": "toggle"})).unwrap();
assert_eq!(s.active().unwrap().selection.partial(d), Some(&[(0, 1)].into()));
}
#[test]