mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Scripts: assigning PageItem.selected keeps how the other objects are selected
Setting selected to true or false runs select.add or select.toggle for that one object, so the other objects keep their direct-selected anchors and segments and the key object. Before, it replaced the selection with whole objects.
This commit is contained in:
1 parent
ba0441c458
commit
5cb6480258
3 files changed
+28
-10
No files matched your search
@@ -1378,17 +1378,15 @@ fn item_selected(h: &Host, a: &[Data]) -> Answer {
|
||||
fn item_set_selected(h: &Host, a: &[Data]) -> Answer {
|
||||
let item = this_item(h, a)?;
|
||||
let on = boolean(arg(a, 1), "selected")?;
|
||||
let mut ids = with_doc(h, item.doc, |_, st| st.selection.objects.clone());
|
||||
if ids.contains(&item.id) == on {
|
||||
if with_doc(h, item.doc, |_, st| st.selection.objects.contains(&item.id)) == on {
|
||||
return Ok(Data::Undefined);
|
||||
}
|
||||
if on {
|
||||
let mut given = selection_ids(h, item.doc, arg(a, 0))?;
|
||||
ids.append(&mut given);
|
||||
} else {
|
||||
ids.retain(|i| *i != item.id);
|
||||
}
|
||||
set_selection(h, item.doc, ids)
|
||||
// Adding or removing the one object keeps how the others are selected (their direct-selected
|
||||
// anchors and segments, and the key object).
|
||||
let ids = if on { selection_ids(h, item.doc, arg(a, 0))? } else { vec![item.id] };
|
||||
let id = if on { "select.add" } else { "select.toggle" };
|
||||
on_doc(h, item.doc.uid, false, |h| command(h, id, &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
|
||||
Ok(Data::Undefined)
|
||||
}
|
||||
|
||||
/// The item's geometric bounds (`visual`: its visible bounds) in document coordinates and the
|
||||
|
||||
@@ -835,6 +835,24 @@ fn headless_add_document_dialog_fails_without_creating() {
|
||||
assert_eq!(s.documents().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_selected_keeps_how_the_other_objects_are_selected() {
|
||||
let (mut s, a, b) = doc();
|
||||
let c = rect(&mut s, 200.0, 100.0, 50.0, 50.0);
|
||||
s.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 0]], "mode": "add"})).unwrap();
|
||||
let anchors = s.active().unwrap().selection.anchors.get(&a).cloned();
|
||||
assert!(anchors.is_some());
|
||||
log(
|
||||
&mut s,
|
||||
"var p = app.activeDocument.pageItems;\
|
||||
for (var i = 0; i < p.length; i++) { if (p[i].left == 200) p[i].selected = true; if (p[i].left == 100) p[i].selected = false; }",
|
||||
);
|
||||
let sel = &s.active().unwrap().selection;
|
||||
assert_eq!(sel.objects, vec![a, c]);
|
||||
assert_eq!(sel.anchors.get(&a).cloned(), anchors, "the direct-selected anchors stay");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_document_takes_only_a_document_preset() {
|
||||
let mut s = Session::new();
|
||||
|
||||
+3
-1
@@ -2644,7 +2644,9 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
has `length`, `[i]`, `index(key)`, `getByName(name)` and `removeAll()`; `i in` either collection is true for each
|
||||
entry `[i]` gives. Each page item
|
||||
(https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/) has `typename`, `parent`, `name`, `note` (the
|
||||
Attributes panel's note, trimmed as `attributes.set` trims it), `hidden`, `locked`, `selected`, `opacity` (0 to
|
||||
Attributes panel's note, trimmed as `attributes.set` trims it), `hidden`, `locked`, `selected` (assigning it adds
|
||||
or removes only that object, as `select.add` and `select.toggle` do, and the other objects stay selected as they
|
||||
were), `opacity` (0 to
|
||||
100), `position`, `left`, `top`, `width`, `height`, `geometricBounds`, `visibleBounds`, `controlBounds` (the
|
||||
visible bounds), `editable`, `zOrderPosition`, `duplicate(relativeObject?, insertionLocation?)`,
|
||||
`move(relativeObject, insertionLocation?)`, `remove()` and `zOrder(method)`
|
||||
|
||||
Reference in new issue
Block a user