Scripts: hasSelectedArtwork selects inside an isolated group and charges its scans

While a group is isolated, `layer.hasSelectedArtwork = true` looked only at
the layer's top-level art, which is not selectable in isolation, so it
selected nothing. It now takes what Select All takes in isolation: the art
inside the isolated group (through any sublayer it holds), or the isolated
object itself, and nothing when the isolated object or what holds it is
hidden or locked. While Lock Guides is on, paths made into guides are not
counted as art to add, so they no longer trip the selection limit.

Reading `hasSelectedArtwork` now counts each selected object it checks
toward the script's operation budget, as the setter already did.

Follows #9048, which added the property.
This commit is contained in:
dotCooCoo committed 2026-12-02 18:44:27 -08:00
1 parent 15cc3b048f
commit 27e10129bd
3 files changed
+91 -4

No files matched your search

+32 -4
View File
@@ -305,7 +305,14 @@ fn layer_z_position(h: &Host, a: &[Data]) -> Answer {
fn layer_has_selected(h: &Host, a: &[Data]) -> Answer {
let (doc, id) = this_layer(h, a)?;
Ok(Data::Bool(with_doc(h, doc, |_, st| st.selection.objects.iter().any(|o| st.doc.ancestry(*o).is_some_and(|a| a.contains(&id))))))
let selected = with_doc(h, doc, |_, st| {
// The scan is charged by every selected object it looks at.
let objects = &st.selection.objects;
let found = objects.iter().position(|o| st.doc.ancestry(*o).is_some_and(|a| a.contains(&id)));
h.charge_call(found.map_or(objects.len(), |i| i + 1) as u64)?;
Ok::<_, HostError>(found.is_some())
})?;
Ok(Data::Bool(selected))
}
/// Collects visible, unlocked art through non-template sublayers, bottom first, and counts every
@@ -332,7 +339,7 @@ fn collect_editable_art(n: &crate::doc::Node, out: &mut Vec<NodeId>) -> u64 {
fn layer_set_has_selected(h: &Host, a: &[Data]) -> Answer {
let on = boolean(arg(a, 1), "hasSelectedArtwork")?;
let (doc, id) = this_layer(h, a)?;
let (ids, over) = with_doc(h, doc, |_, st| {
let (ids, over) = with_doc(h, doc, |s, st| {
let inside = |o: &NodeId| st.doc.ancestry(*o).is_some_and(|a| a.contains(&id));
let selected = &st.selection.objects;
h.charge_call(selected.len() as u64)?;
@@ -345,10 +352,31 @@ fn layer_set_has_selected(h: &Host, a: &[Data]) -> Answer {
// The walk is charged by every node it looks at, hidden and locked ones included, whether
// or not anything is added.
h.charge_call(count)?;
// While an object is isolated, the art that holds it is replaced by the isolated object,
// or by what an isolated group or other container holds, as Select All takes it.
let isolated = st.isolation.and_then(|i| st.doc.node(i));
let path = isolated.and_then(|c| st.doc.ancestry(c.id)).unwrap_or_default();
let editable = path.iter().all(|i| st.doc.node(*i).is_some_and(|n| n.visible && !n.locked && !n.is_template()));
let mut candidates = Vec::with_capacity(art.len());
for o in art {
match isolated {
Some(_) if path.contains(&o) && !editable => {}
Some(c) if path.contains(&o) && c.is_container() => {
// The same walk as the layer's, through any sublayer the container holds.
let visited = collect_editable_art(c, &mut candidates);
h.charge_call(visited)?;
}
Some(c) if path.contains(&o) => candidates.push(c.id),
_ => candidates.push(o),
}
}
let mut have: std::collections::HashSet<NodeId> = selected.iter().copied().collect();
let mut ids = Vec::new();
for o in art {
if have.contains(&o) || !crate::cmd::select::is_selectable(&st.doc, st.isolation, &locks, o) {
for o in candidates {
if have.contains(&o)
|| !crate::cmd::select::is_selectable(&st.doc, st.isolation, &locks, o)
|| (s.guides_locked() && crate::is_guide_path(&st.doc, o))
{
continue;
}
// Only art that would be added counts toward the limit.