Merge pull request #10628 from dotCooCoo/fix/script-remove-trace-source

Scripts: remove() refuses a tracing's shown source image
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-04 15:29:17 -08:00
commit 88694da6eb
4 files changed
+34 -4

No files matched your search

+9 -2
View File
@@ -146,6 +146,8 @@ pub const STALE_ITEM: &str = "Stale page item";
const TRACING_NAME: &str = "The name of a tracing cannot be changed";
/// The error for the tracing's name given to a group that holds an image first.
const NOT_A_TRACING: &str = "Only Image Trace can make a tracing";
/// The error of `move` and `remove()` for a tracing's source image.
const SOURCE_STAYS: &str = "a tracing's source image cannot leave its tracing";
/// The error for a document that was closed, or that came from an earlier run.
pub const STALE_DOCUMENT: &str = "Stale document";
/// The error of `index` and `getByName` when nothing matches.
@@ -2895,7 +2897,8 @@ fn item_z_order_position(h: &Host, a: &[Data]) -> Answer {
/// `remove()`: deletes the object. A hidden or locked object, one in a hidden or locked layer or
/// group, a group holding one, or an object on a locked artboard is refused, as [`items_remove_all`]
/// refuses it. A compound path whose last path this is stays, empty.
/// refuses it. A tracing's source image is refused when it is shown as well. A compound path whose
/// last path this is stays, empty.
fn item_remove(h: &Host, a: &[Data]) -> Answer {
let item = this_item(h, a)?;
let (whole, on_locked) = with_doc(h, item.doc, |_, st| {
@@ -2907,6 +2910,10 @@ fn item_remove(h: &Host, a: &[Data]) -> Answer {
if on_locked {
return Err(HostError::Error(format!("{ON_LOCKED_ARTBOARD}: {}", item.id.0)));
}
// A tracing keeps its source image when a script has shown it, as `move` keeps it there.
if with_doc(h, item.doc, |_, st| crate::cmd::is_trace_source(&st.doc, item.id)) {
return Err(HostError::Error(SOURCE_STAYS.into()));
}
// An image left first in an ordinary group named as a tracing would make that group one.
if with_doc(h, item.doc, |_, st| st.doc.parent_of(item.id).is_some_and(|p| makes_tracing(&st.doc, p, item.id, None))) {
return Err(HostError::Error(NOT_A_TRACING.into()));
@@ -3133,7 +3140,7 @@ fn place(h: &Host, doc: Doc, id: NodeId, to: &Destination) -> std::result::Resul
if d.parent_of(id) == Some(to.parent) {
return Ok(0);
}
return Err(HostError::Error("a tracing's source image cannot leave its tracing".into()));
return Err(HostError::Error(SOURCE_STAYS.into()));
}
let clips = d.node(to.parent).is_some_and(|n| n.clips() || crate::cmd::is_trace_group(n)) && count > 0;
// The clipping path itself, put back where it is, stays the clipping path.