mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Scripts: removeAll cannot leave an image first in a group named Image Trace
textFrames.removeAll() and the removeAll() of a group's pageItems, groupItems and compoundPathItems checked only clip groups whose mask they release. Deleting the type or art below an image in an ordinary group named Image Trace left the image first, so the group was read as a tracing and the image dropped out of pageItems. Both now throw "Only Image Trace can make a tracing" and delete nothing, checking the whole set being deleted at once.
This commit is contained in:
1 parent
72e99d1c3b
commit
3d69c8d49a
5 files changed
+73
-2
No files matched your search
@@ -3049,6 +3049,19 @@ fn makes_tracing(d: &Document, parent: NodeId, id: NodeId, at: Option<usize>) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether deleting every object in `removed` together would leave one of their parents, an
|
||||
/// ordinary group named as a tracing, with an image first in it, which would make it a tracing.
|
||||
pub(super) fn removal_makes_tracing(d: &Document, removed: &[NodeId]) -> bool {
|
||||
let going: std::collections::HashSet<NodeId> = removed.iter().copied().collect();
|
||||
let mut parents: Vec<NodeId> = removed.iter().filter_map(|i| d.parent_of(*i)).collect();
|
||||
parents.sort_unstable_by_key(|p| p.0);
|
||||
parents.dedup();
|
||||
parents
|
||||
.into_iter()
|
||||
.filter(|p| named_as_tracing(d, *p))
|
||||
.any(|p| d.children(Some(p)).and_then(|c| c.iter().find(|n| !going.contains(&n.id))).is_some_and(|n| matches!(n.kind, NodeKind::Image(_))))
|
||||
}
|
||||
|
||||
/// Moves the object `id` to `to` with `node.move`, its index worked out once it has left its place.
|
||||
fn place(h: &Host, doc: Doc, id: NodeId, to: &Destination) -> std::result::Result<(), HostError> {
|
||||
let index = with_doc(h, doc, |_, st| {
|
||||
|
||||
@@ -855,6 +855,10 @@ fn art_remove_all(h: &Host, a: &[Data], kind: Kind) -> Answer {
|
||||
"cannot delete a clipping path while its group or layer keeps other objects; release the clipping mask first: {list}"
|
||||
)));
|
||||
}
|
||||
// Deleting the objects above an image in an ordinary group named as a tracing would make it one.
|
||||
if with_doc(h, doc, |_, st| super::removal_makes_tracing(&st.doc, &ids)) {
|
||||
return Err(HostError::Error(super::NOT_A_TRACING.into()));
|
||||
}
|
||||
if !ids.is_empty() {
|
||||
on_doc(h, doc.uid, true, |h| command(h, "edit.clear", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>(), "keepEmpty": true})))?;
|
||||
}
|
||||
|
||||
@@ -1542,7 +1542,8 @@ fn frames_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
// Type that clips a group or layer releases its mask, so the object above it is not made
|
||||
// the clipping path.
|
||||
let released = super::masks_cleared_by(&st.doc, &ids);
|
||||
let tracing = super::release_makes_tracing(&st.doc, &released, &ids);
|
||||
// So would deleting the type above an image in an ordinary group named as a tracing.
|
||||
let tracing = super::release_makes_tracing(&st.doc, &released, &ids) || super::removal_makes_tracing(&st.doc, &ids);
|
||||
Ok::<_, HostError>((ids, refused, on_locked, released, tracing))
|
||||
})?;
|
||||
if !refused.is_empty() {
|
||||
|
||||
Reference in new issue
Block a user