diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index 66724c0fcc..22e619a910 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -240,10 +240,6 @@ pub(super) struct State { /// A path and its subpaths with the point changes the run has made to it and not written yet /// ([`flush`]). pending: RefCell)>>, - /// The paths with no points, by document uid, revert count and id, that a script set `closed` - /// on: the points `setEntirePath` gives them later make a closed path. A command's steps share - /// the set without copying it ([`super::StyleTrail`]). - pub(super) closed_empty: RefCell>>, /// The index of the first point of each subpath of the path whose points the run read last, /// and what they were counted from ([`paths`]). point_starts: RefCell>)>>, @@ -1101,7 +1097,6 @@ fn ends_run(e: &HostError) -> bool { /// the swatches, symbols, styles and brushes it removed or renamed with the ones earlier commands /// removed. pub(super) fn after_kept_command(h: &Host) { - paths::forget_closed_empty(h); let (taken, scanned) = { let mut s = h.session.borrow_mut(); let trail = &mut s.script_style_trail; diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index 441611fd03..5bb5e31801 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -299,37 +299,14 @@ fn edit_points_keeping( if !counts_kept { forget_waiting_starts(h); } - // A path that has or gains points keeps its own closed state from then on ([`is_closed`]). - let gained = |gained: bool| { - if gained { - let key = closed_key(h, item); - let mut held = h.dom.closed_empty.borrow_mut(); - if held.contains(&key) { - Arc::make_mut(&mut held).remove(&key); - } - } - }; - let mut f = Some(f); - let accepted = if let Some((waiting, subs)) = &mut *h.dom.pending.borrow_mut() + if let Some((waiting, subs)) = &mut *h.dom.pending.borrow_mut() && same_path(*waiting, item) - && let Some(f) = f.take() { - let had = !subs.is_empty(); - let r = f(subs); - Some((r, had || !subs.is_empty())) - } else { - None - }; - if let Some((r, has_points)) = accepted { - gained(has_points); - return Ok(r); + return Ok(f(subs)); } - let Some(f) = f else { return Err(HostError::Error(STALE_ITEM.into())) }; flush(h)?; let mut subs = read_path(h, item, |_, _, pd| pd.subpaths.clone())?; - let had = !subs.is_empty(); let r = f(&mut subs); - let has_points = had || !subs.is_empty(); let (same, refused, aligned) = read_path(h, item, |st, _, pd| { let d = &st.doc; let aligned = d.ancestry(item.id).is_some_and(|a| a.iter().chain([&item.id]).any(|i| d.node(*i).is_some_and(|n| n.extras().pixel_aligned))); @@ -345,35 +322,9 @@ fn edit_points_keeping( flush(h)?; } } - gained(has_points); Ok(r) } -/// The key of the path of `item` among the empty paths a script set `closed` on: its document's -/// uid and revert count, so a revert drops the setting, and its id. -fn closed_key(h: &super::Host, item: Item) -> (u64, u64, NodeId) { - (item.doc.uid, with_doc(h, item.doc, |_, st| st.reverts), item.id) -} - -/// Drops empty-path closed settings after a kept command gives a path points or removes it. -pub(super) fn forget_closed_empty(h: &super::Host) { - let s = h.session.borrow(); - let keep = |(uid, reverts, id): &(u64, u64, NodeId)| { - !s.script_style_trail.paths_with_points.contains(&(*uid, *reverts, *id)) - && s.documents() - .iter() - .find(|st| st.uid == *uid && st.reverts == *reverts) - .and_then(|st| st.doc.node(*id)) - .and_then(|n| n.path_data()) - .is_some_and(|pd| pd.subpaths.is_empty()) - }; - let mut held = h.dom.closed_empty.borrow_mut(); - // The set is copied only when another holder shares it and a setting ends. - if !held.iter().all(keep) { - Arc::make_mut(&mut held).retain(keep); - } -} - /// Drops the [`starts`] that [`super::State`] keeps of waiting point changes, which a change can /// make wrong. fn forget_waiting_starts(h: &super::Host) { @@ -1116,11 +1067,10 @@ fn path_points(h: &super::Host, a: &[Data]) -> Answer { Ok(host_ref("PathPoints", &handle)) } -/// Whether the path of `item` is closed: every subpath is, or, for a path with no points, a script -/// set `closed` on it. +/// Whether the path of `item` is closed: it has a subpath and every subpath is. Setting `closed` on +/// a path with no subpath gives it an empty closed one ([`path_set_closed`]). fn is_closed(h: &super::Host, item: Item) -> std::result::Result { - let (empty, closed) = read_points(h, item, |subs| (subs.is_empty(), subs.iter().all(|sp| sp.closed)))?; - Ok(if empty { h.dom.closed_empty.borrow().contains(&closed_key(h, item)) } else { closed }) + read_points(h, item, |subs| !subs.is_empty() && subs.iter().all(|sp| sp.closed)) } fn path_closed(h: &super::Host, a: &[Data]) -> Answer { diff --git a/crates/engine/src/script/mod.rs b/crates/engine/src/script/mod.rs index acf316a5a5..ce47075a39 100644 --- a/crates/engine/src/script/mod.rs +++ b/crates/engine/src/script/mod.rs @@ -1406,7 +1406,7 @@ fn note_ids(s: &mut Session) { /// it, for a result that cannot cross to the script. fn step(s: &mut Session, host: &Host, id: &str, params: &Value) -> Result<(Value, u64, u64, Option)> { raise_ids(s); - s.script_style_trail = StyleTrail::start(s, dom::holds_resources(host), host.dom.closed_empty.borrow().clone()); + s.script_style_trail = StyleTrail::start(s, dom::holds_resources(host)); let mutating = waits_for_tool_edit(id); // Inside an object-model call's own savepoint ([`dom`]), that savepoint puts a failure back. A // query that fills the clipboard (`clipboard.importSvg`) takes one too, for the clipboard. @@ -1517,12 +1517,7 @@ fn command_crossing(host: &Host, id: &str, params: &Value, cross: bool) -> std:: let before = dom::before_command(host, id); let (copies, r) = { let mut s = session.borrow_mut(); - let copies = s.copies; - let r = step(&mut s, host, id, params); - // The steps are done with the empty-path closed settings, so the object model can change - // them again without copying them. - s.script_style_trail.closed_empty = Arc::default(); - (copies, r) + (s.copies, step(&mut s, host, id, params)) }; // The resource names a failed command's steps compared are still charged, before its error is // given. @@ -1608,18 +1603,15 @@ pub(crate) struct StyleTrail { pub(in crate::script) resources_gone: std::collections::HashSet<(u64, dom::ResourceKind, String)>, /// The resource names the steps compared, charged to the run with the check that follows. pub(crate) resources_scanned: u64, - /// The object model's empty-path closed settings, shared with it while the steps run. - closed_empty: Arc>, - pub(in crate::script) paths_with_points: std::collections::HashSet<(u64, u64, NodeId)>, } impl StyleTrail { /// A trail that starts from the documents' style lists now, and from the documents themselves /// when `watch_resources`. - fn start(s: &Session, watch_resources: bool, closed_empty: Arc>) -> Self { + fn start(s: &Session, watch_resources: bool) -> Self { let lists = s.docs.iter().map(|st| (st.uid, st.reverts, st.doc.char_styles.clone(), st.doc.para_styles.clone())).collect(); let docs = if watch_resources { s.docs.iter().map(|st| (st.uid, st.doc.clone())).collect() } else { Vec::new() }; - StyleTrail { lists, docs, watch_resources, closed_empty, ..Default::default() } + StyleTrail { lists, docs, watch_resources, ..Default::default() } } } @@ -1629,17 +1621,6 @@ impl StyleTrail { /// document's lists, however many steps change them. pub(crate) fn note_style_lists(s: &mut Session) { let trail = &mut s.script_style_trail; - for &(uid, reverts, id) in trail.closed_empty.iter() { - if s.docs - .iter() - .find(|st| st.uid == uid && st.reverts == reverts) - .and_then(|st| st.doc.node(id)) - .and_then(|n| n.path_data()) - .is_some_and(|pd| !pd.subpaths.is_empty()) - { - trail.paths_with_points.insert((uid, reverts, id)); - } - } trail.lists.retain(|(uid, ..)| s.docs.iter().any(|d| d.uid == *uid)); for st in &s.docs { let (c, p) = (&st.doc.char_styles, &st.doc.para_styles);