mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Scripts: deleting a clipping path cannot make a tracing
remove(), the document's pageItems.removeAll() and textFrames.removeAll() release the mask of a clip group whose clipping path they delete. A clip group named Image Trace with an image next above its clipping path then became an ordinary group named as a tracing with an image first, which reads as a tracing. They now throw "Only Image Trace can make a tracing" and delete nothing in that case. docs/mcp.md names the removeAll() collections that release a mask and the ones that refuse to delete a clipping path instead.
This commit is contained in:
1 parent
0d8a56cfde
commit
80569dc577
4 files changed
+83
-7
No files matched your search
@@ -2337,7 +2337,7 @@ fn items_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
return layers::scoped_remove_all(h, a);
|
||||
}
|
||||
let doc = items_doc(h, a)?;
|
||||
let (ids, refused, on_locked, released) = with_doc(h, doc, |_, st| {
|
||||
let (ids, refused, on_locked, released, tracing) = with_doc(h, doc, |_, st| {
|
||||
let ids = top_items(&st.doc);
|
||||
let whole = |id: &NodeId| editable(&st.doc, *id) && st.doc.node(*id).is_some_and(all_editable);
|
||||
let refused: Vec<u64> = ids.iter().filter(|i| !whole(i)).map(|i| i.0).take(20).collect();
|
||||
@@ -2346,7 +2346,8 @@ fn items_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
// A clipping layer emptied of its art releases its mask, so art added later is not made its
|
||||
// clipping path.
|
||||
let released = masks_cleared_by(&st.doc, &ids);
|
||||
(ids, refused, on_locked, released)
|
||||
let tracing = release_makes_tracing(&st.doc, &released, &ids);
|
||||
(ids, refused, on_locked, released, tracing)
|
||||
});
|
||||
if !refused.is_empty() {
|
||||
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
|
||||
@@ -2356,6 +2357,9 @@ fn items_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
|
||||
return Err(HostError::Error(format!("{ON_LOCKED_ARTBOARD}: {list}")));
|
||||
}
|
||||
if tracing {
|
||||
return Err(HostError::Error(NOT_A_TRACING.into()));
|
||||
}
|
||||
if !ids.is_empty() {
|
||||
on_doc(h, doc.uid, true, |h| clear_releasing(h, &released, &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})))?;
|
||||
}
|
||||
@@ -2851,6 +2855,10 @@ fn item_remove(h: &Host, a: &[Data]) -> Answer {
|
||||
return Err(HostError::Error(NOT_A_TRACING.into()));
|
||||
}
|
||||
let released = with_doc(h, item.doc, |_, st| masks_cleared_by(&st.doc, &[item.id]));
|
||||
// A clip group named as a tracing, released with an image left first, would become one too.
|
||||
if with_doc(h, item.doc, |_, st| release_makes_tracing(&st.doc, &released, &[item.id])) {
|
||||
return Err(HostError::Error(NOT_A_TRACING.into()));
|
||||
}
|
||||
// A compound path whose last path this is stays, empty, as it does after `move`.
|
||||
let params = json!({"ids": [item.id.0], "keepEmpty": true});
|
||||
paths::see_all_points(h);
|
||||
@@ -2873,6 +2881,20 @@ pub(super) fn masks_cleared_by(d: &Document, ids: &[NodeId]) -> Vec<NodeId> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether releasing the masks of `released` and deleting `removed` would leave one of those groups
|
||||
/// an ordinary group named as a tracing with an image first in it, which would make it a tracing.
|
||||
pub(super) fn release_makes_tracing(d: &Document, released: &[NodeId], removed: &[NodeId]) -> bool {
|
||||
if released.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let removed: std::collections::HashSet<NodeId> = removed.iter().copied().collect();
|
||||
released.iter().filter_map(|g| d.node(*g)).any(|g| {
|
||||
matches!(g.kind, NodeKind::Group { .. })
|
||||
&& g.name.as_deref() == Some(crate::cmd::TRACE_NAME)
|
||||
&& g.children().and_then(|c| c.iter().find(|n| !removed.contains(&n.id))).is_some_and(|n| matches!(n.kind, NodeKind::Image(_)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Releases the masks of `released` ([`masks_cleared_by`]), then runs `edit.clear` with `params`.
|
||||
pub(super) fn clear_releasing(h: &Host, released: &[NodeId], params: &Value) -> std::result::Result<Data, HostError> {
|
||||
for g in released {
|
||||
|
||||
@@ -1480,7 +1480,7 @@ fn frames_path_text(h: &Host, a: &[Data]) -> Answer {
|
||||
/// locked one, or one on a locked artboard, stops it first, as `PageItems.removeAll()` does.
|
||||
fn frames_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
let (doc, c) = frames_scope(h, a)?;
|
||||
let (ids, refused, on_locked, released) = with_doc(h, doc, |_, st| {
|
||||
let (ids, refused, on_locked, released, tracing) = with_doc(h, doc, |_, st| {
|
||||
let ids = listed(h, st, c)?;
|
||||
let ok = |id: &NodeId| editable(&st.doc, *id) && st.doc.node(*id).is_some_and(all_editable);
|
||||
let refused: Vec<u64> = ids.iter().filter(|i| !ok(i)).map(|i| i.0).take(20).collect();
|
||||
@@ -1489,7 +1489,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);
|
||||
Ok::<_, HostError>((ids, refused, on_locked, released))
|
||||
let tracing = super::release_makes_tracing(&st.doc, &released, &ids);
|
||||
Ok::<_, HostError>((ids, refused, on_locked, released, tracing))
|
||||
})?;
|
||||
if !refused.is_empty() {
|
||||
let list = refused.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
|
||||
@@ -1499,6 +1500,10 @@ fn frames_remove_all(h: &Host, a: &[Data]) -> Answer {
|
||||
let list = on_locked.iter().map(u64::to_string).collect::<Vec<_>>().join(", ");
|
||||
return Err(HostError::Error(format!("{}: {list}", super::ON_LOCKED_ARTBOARD)));
|
||||
}
|
||||
// A clip group named as a tracing, released with an image left first, would become one.
|
||||
if tracing {
|
||||
return Err(HostError::Error(super::NOT_A_TRACING.into()));
|
||||
}
|
||||
if !ids.is_empty() {
|
||||
let params = json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()});
|
||||
super::atomically(h, |h| on_doc(h, doc.uid, true, |h| super::clear_releasing(h, &released, ¶ms)))?;
|
||||
|
||||
Reference in new issue
Block a user