mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
Scripts: assigning selected keeps other objects' direct-selected anchors
Setting a page item's `selected` rebuilt the selection with select.set, which selects every object whole, so the direct-selected anchors and segments of the other selected objects were lost. When another object has some, the selection is now rebuilt the way an edit restores it, with only the item added or removed.
This commit is contained in:
1 parent
bb931b5df7
commit
74fefce46f
3 files changed
+38
-2
No files matched your search
@@ -1373,7 +1373,27 @@ fn item_set_selected(h: &Host, a: &[Data]) -> Answer {
|
||||
} else {
|
||||
ids.retain(|i| *i != item.id);
|
||||
}
|
||||
set_selection(h, item.doc, ids)
|
||||
// The direct-selected anchors and segments of the other objects stay selected.
|
||||
let partial = with_doc(h, item.doc, |_, st| {
|
||||
let sel = &st.selection;
|
||||
let plain = sel.target.is_none() && sel.symbol_part.is_none() && sel.on_path_member.is_none() && sel.slices.is_empty();
|
||||
(plain && ids.iter().any(|i| sel.anchors.contains_key(i) || sel.segments.contains_key(i))).then(|| {
|
||||
let mut next = sel.clone();
|
||||
next.objects.clone_from(&ids);
|
||||
next.anchors.retain(|i, _| ids.contains(i));
|
||||
next.segments.retain(|i, _| ids.contains(i));
|
||||
next.key = next.key.filter(|k| ids.contains(k));
|
||||
next.key_anchor = next.key_anchor.filter(|(k, _)| ids.contains(k));
|
||||
(st.doc.clone(), next)
|
||||
})
|
||||
});
|
||||
match partial {
|
||||
Some((doc, next)) => {
|
||||
on_doc(h, item.doc.uid, false, |h| restore_selection(h, &doc, &next))?;
|
||||
Ok(Data::Undefined)
|
||||
}
|
||||
None => set_selection(h, item.doc, ids),
|
||||
}
|
||||
}
|
||||
|
||||
/// The item's geometric bounds (`visual`: its visible bounds) in document coordinates and the
|
||||
|
||||
@@ -536,6 +536,21 @@ fn an_edit_keeps_direct_selected_anchors() {
|
||||
assert!(s.journal.iter().any(|(id, _)| id == "select.anchorsMany"), "the journal holds the restore");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selecting_an_item_keeps_the_direct_selected_anchors_of_others() {
|
||||
let (mut s, a, b) = doc();
|
||||
s.execute("select.anchors", &json!({"id": a.0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
|
||||
s.execute("select.add", &json!({"ids": [b.0]})).unwrap();
|
||||
let anchors = s.active().unwrap().selection.anchors.clone();
|
||||
assert!(anchors.contains_key(&a));
|
||||
log(&mut s, "app.activeDocument.pageItems[1].selected = false;");
|
||||
let sel = &s.active().unwrap().selection;
|
||||
assert_eq!((sel.objects.clone(), sel.anchors.clone()), (vec![a], anchors.clone()));
|
||||
log(&mut s, "app.activeDocument.pageItems[1].selected = true;");
|
||||
let sel = &s.active().unwrap().selection;
|
||||
assert_eq!((sel.objects.clone(), sel.anchors.get(&a)), (vec![a, b], anchors.get(&a)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_keeps_the_order_of_a_mixed_selection() {
|
||||
let (mut s, a, b) = doc();
|
||||
|
||||
+2
-1
@@ -2672,7 +2672,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot
|
||||
`Not found`; and
|
||||
`app.activeDocument` with no document open throws `No active document`. `Document.selection` takes one page item,
|
||||
a list of at most 10,000, `null` or `[]`, and an object that cannot be selected throws `Cannot select` with
|
||||
nothing changed. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
|
||||
nothing changed. Assigning a page item's `selected` leaves the direct-selected anchors and segments of the other
|
||||
selected objects selected. `getIsFileOpen` compares the path with the open documents' files as text (in a Windows path,
|
||||
letter case is ignored and `\` matches `/`) and does not resolve the path it is given. A document counts only when
|
||||
the automation read roots allow its file, and that check can look the document's file up on disk. A path with
|
||||
`..`, a network path, a NUL character or more than 4,096 bytes throws an error. Some members the Application,
|
||||
|
||||
Reference in new issue
Block a user