Merge main into fix/retrace-keeps-note-and-tags

This commit is contained in:
dotCooCoo committed 2026-12-04 19:07:21 -08:00
commit 8ecc2fd568
43 files changed
+2939 -116

No files matched your search

+30 -12
View File
@@ -203,15 +203,22 @@ pub(super) fn remember_source(h: &Host, uid: u64, group: &Node) {
}
h.dom.tracing.descendants.borrow_mut().entry((uid, group.id.0)).or_insert_with(|| {
let mut ids = HashSet::new();
group.walk(&mut |n| {
if n.id != group.id {
ids.insert(n.id);
}
});
// Only children are recorded: an opacity mask is refused whatever its art, so the art of
// one held now must not become an object the trace made if the mask is later undone.
let mut todo: Vec<&Node> = group.children().into_iter().flatten().map(|c| &**c).collect();
while let Some(n) = todo.pop() {
ids.insert(n.id);
todo.extend(n.children().into_iter().flatten().map(|c| &**c));
}
ids
});
}
/// The objects `n` holds: its children and the art of its opacity mask.
fn members(n: &Node) -> impl Iterator<Item = &Node> {
n.children().into_iter().flatten().map(|c| &**c).chain(n.extras().mask.as_deref().map(|m| &*m.art))
}
/// Before each command a script runs: notes the active document ([`note_document`]).
pub(super) fn before_command(h: &Host) {
let s = h.session.borrow();
@@ -357,6 +364,7 @@ fn replace(h: &Host, item: Item, id: &str, params: &Value, key: &str) -> Result<
}
/// Throws `refusal` when the Image Trace object of `item` holds an object its trace did not make,
/// or has an opacity mask on it or on one of its objects other than the source image, whatever its art,
/// and "Cannot edit page item" when it holds a locked object other than its source image, which
/// the replacement would discard. The objects looked at are charged to the run either way.
fn refuse_added(h: &Host, item: Item, refusal: &str) -> Result<(), HostError> {
@@ -380,14 +388,22 @@ fn refuse_added(h: &Host, item: Item, refusal: &str) -> Result<(), HostError> {
let source = group.children().and_then(|c| c.first()).map(|n| n.id);
let mut visited = 0u64;
let mut locked = None;
let mut todo: Vec<&Arc<Node>> = group.children().map(|c| c.iter().collect()).unwrap_or_default();
// An opacity mask on the tracing or on an object other than the source image is added
// artwork whatever the ids of its art: a mask made from traced objects keeps their ids.
if group.extras().mask.is_some() {
return Ok((visited, Err(HostError::Error(refusal.into()))));
}
// The tracing's own opacity mask goes with it too; the source image is kept whole.
let mut todo: Vec<&Node> = members(group).collect();
while let Some(n) = todo.pop() {
visited += 1;
let added = match (&made, ids) {
(Some(m), _) => !m.contains(n.id),
(None, Some(ids)) => !ids.contains(&n.id),
(None, None) => false,
} || newer.is_some_and(|m| n.id.0 >= m);
let added = (Some(n.id) != source && n.extras().mask.is_some())
|| match (&made, ids) {
(Some(m), _) => !m.contains(n.id),
(None, Some(ids)) => !ids.contains(&n.id),
(None, None) => false,
}
|| newer.is_some_and(|m| n.id.0 >= m);
// Added artwork is reported before a locked object, whichever comes first.
if added {
return Ok((visited, Err(HostError::Error(refusal.into()))));
@@ -395,7 +411,9 @@ fn refuse_added(h: &Host, item: Item, refusal: &str) -> Result<(), HostError> {
if n.locked && Some(n.id) != source && locked.is_none() {
locked = Some(n.id);
}
todo.extend(n.children().into_iter().flatten());
if Some(n.id) != source {
todo.extend(members(n));
}
}
Ok((visited, locked.map_or(Ok(()), |id| Err(HostError::Error(format!("Cannot edit page item {}", id.0))))))
})?;