Scripts: review fixes for the document defaults and the object model

- appearance.setNewArt is listed among the commands a plug-in may call, so
  every_command_is_reviewed passes.
- appearance.setNewArt refuses `tint` on a pattern that has no swatch entry,
  and its help and docs/mcp.md say an omitted `weight` keeps the stored weight.
- The dash checks of appearance.setNewArt, strokeDashes and
  defaultStrokeDashes share one helper.
- defaultStrokeWidth, defaultStrokeMiterLimit and defaultStrokeDashOffset
  compare exactly, so a slightly different value reaches new art.
- An RGB default in a CMYK document is compared in the document's color mode,
  and a color read back from a path or a default (a Gray too small for its
  value to name) assigns back without a command.
- addDocument starts from the profile's built-in first preset even when a
  saved preset has the same name.
- A saved preset's rows are read as at most 1000.
- The page item and path lists are kept for each open document, the
  selection list stops at its limit, the typename of a removed PathPoint and
  of a stale PathPoints or PathItems throws, and an item edit whose
  selection cannot be restored is undone with it.
- A path's subpath starts are counted once and kept while its points keep
  their layout, so reading or setting each of its points in turn no longer
  walks every subpath for each point.
- A run that ended while waiting for a growth answer is checked against its
  allowance again before it is kept.
- docs/mcp.md says which file limits apply to reading a profile's file.
This commit is contained in:
dotCooCoo committed 2026-11-25 15:07:36 -08:00
1 parent a61c4d87e8
commit f5afa0b84a
14 files changed
+425 -89

No files matched your search

+68 -20
View File
@@ -96,12 +96,15 @@ const ARTBOARD_COORDS: &str = "CoordinateSystem.ARTBOARDCOORDINATESYSTEM";
#[derive(Default)]
pub(super) struct State {
coords: Cell<Coords>,
items: RefCell<Option<ItemList>>,
/// The last list of a document's paths ([`paths`]), kept while that document is unchanged.
paths: RefCell<Option<ItemList>>,
items: RefCell<Vec<ItemList>>,
/// The last list of each document's paths ([`paths`]), kept while that document is unchanged.
paths: RefCell<Vec<ItemList>>,
/// A path and its subpaths with the point changes the run has made to it and not written yet
/// ([`flush`]).
pending: RefCell<Option<(Item, Vec<vectorcraft_geom::path::SubPath>)>>,
/// 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<Option<(paths::Counted, Rc<Vec<usize>>)>>,
/// How many times the points the run read of each path went stale, by document uid and path id
/// ([`paths`]).
point_cuts: RefCell<std::collections::HashMap<(u64, u64), u64>>,
@@ -148,6 +151,24 @@ fn atomically<T>(h: &Host, f: impl FnOnce(&Host) -> std::result::Result<T, HostE
/// A document's uid, the document as it was, and the ids of its page items then.
type ItemList = (u64, Arc<Document>, Rc<Vec<NodeId>>);
/// The most documents whose lists [`State`] keeps at once, the least recently listed going first.
const KEPT_LISTS: usize = 8;
/// The list kept in `lists` for the document `st`, while that document is unchanged.
fn kept_list(lists: &RefCell<Vec<ItemList>>, st: &DocState) -> Option<Rc<Vec<NodeId>>> {
lists.borrow().iter().find(|(uid, doc, _)| *uid == st.uid && Arc::ptr_eq(doc, &st.doc)).map(|(_, _, ids)| ids.clone())
}
/// Keeps `ids` in `lists` as the list of the document `st`, in place of the one it had.
fn keep_list(lists: &RefCell<Vec<ItemList>>, st: &DocState, ids: &Rc<Vec<NodeId>>) {
let mut l = lists.borrow_mut();
l.retain(|(uid, ..)| *uid != st.uid);
if l.len() >= KEPT_LISTS {
l.remove(0);
}
l.push((st.uid, st.doc.clone(), ids.clone()));
}
type Answer = std::result::Result<Data, HostError>;
/// A member function: the run's host and the call's arguments, `this` first.
@@ -396,13 +417,11 @@ fn item_ref(h: &Host, st: &DocState, id: NodeId) -> Data {
}
}
/// The ids of a document's page items in paint order ([`State`] keeps the last list).
/// The ids of a document's page items in paint order ([`State`] keeps the last list of each
/// document).
fn page_items(h: &Host, st: &DocState) -> Rc<Vec<NodeId>> {
if let Some((uid, doc, ids)) = &*h.dom.items.borrow()
&& *uid == st.uid
&& Arc::ptr_eq(doc, &st.doc)
{
return ids.clone();
if let Some(ids) = kept_list(&h.dom.items, st) {
return ids;
}
fn walk(nodes: &[Arc<crate::doc::Node>], out: &mut Vec<NodeId>) {
for n in nodes {
@@ -420,7 +439,7 @@ fn page_items(h: &Host, st: &DocState) -> Rc<Vec<NodeId>> {
let mut ids = Vec::new();
walk(&st.doc.layers, &mut ids);
let ids = Rc::new(ids);
*h.dom.items.borrow_mut() = Some((st.uid, st.doc.clone(), ids.clone()));
keep_list(&h.dom.items, st, &ids);
ids
}
@@ -639,12 +658,13 @@ fn on_doc<T>(
Ok(v)
}
/// Runs `id` with `params` on the item's document, its selection kept. The points the run read of
/// the item's paths stay valid through the change ([`paths::see_all_points`]).
/// Runs `id` with `params` on the item's document, its selection kept, as one change: when the
/// selection cannot be put back, the edit is undone too. The points the run read of the item's
/// paths stay valid through the change ([`paths::see_all_points`]).
fn edit_item(h: &Host, item: Item, id: &str, params: &Value) -> std::result::Result<Data, HostError> {
paths::see_all_points(h);
let kept = h.dom.editing.replace(Some(item));
let r = on_doc(h, item.doc.uid, true, |h| command(h, id, params));
let r = atomically(h, |h| on_doc(h, item.doc.uid, true, |h| command(h, id, params)));
h.dom.editing.set(kept);
r
}
@@ -934,6 +954,22 @@ fn startup_preset(name: &str) -> Option<(Option<&'static str>, Option<&'static s
})
}
/// The `file.newPresets` fields `addDocument` gives `file.new`: those of the profile's first
/// built-in preset with `presetSettings` over them.
const BUILT_IN_SETTINGS: &[&str] = &[
"width",
"height",
"units",
"artboards",
"artboardLayout",
"bleed",
"backgroundContents",
"colorMode",
"rasterEffectsPpi",
"previewMode",
"alignNewObjectsToPixelGrid",
];
/// `documents.addDocument(startupPreset, presetSettings?, showOptionsDialog?)`: a new document from
/// the New Document profile `startupPreset` names, with the settings `presetSettings` gives in
/// place of the profile's.
@@ -977,15 +1013,26 @@ fn docs_add_document(h: &Host, a: &[Data]) -> Answer {
Some(Data::Bool(true)) => return Err(HostError::Error(DIALOG_UNAVAILABLE.into())),
Some(_) => return Err(HostError::Type("showOptionsDialog must be true or false".into())),
}
// The document starts from the first preset of the profile's category (Print: Letter).
let first = profile.and_then(|n| crate::cmd::newdoc::category(&h.session.borrow(), n)?.into_iter().next());
if let Some(first) = first {
p.insert("preset".into(), json!(first.name));
}
p.insert("profile".into(), profile.map_or(Value::Null, |n| json!(n)));
if let Some(m) = mode {
p.entry("colorMode").or_insert_with(|| json!(m));
}
// The document starts from the first built-in preset of the profile's category (Print:
// Letter) with `presetSettings` over it, given in full so that a saved preset of the same name
// does not stand in for it. Settings `file.new` refuses are left for it to report.
let first = profile.and_then(|n| crate::cmd::newdoc::category(&h.session.borrow(), n)?.into_iter().next());
if let Some(first) = first {
p.insert("preset".into(), json!(first.name));
if let Ok(full) = first.with_params(&Value::Object(p.clone()), "file.new")
&& let Value::Object(settings) = full.to_json()
{
for key in BUILT_IN_SETTINGS {
if let Some(v) = settings.get(*key) {
p.insert((*key).into(), v.clone());
}
}
}
}
p.insert("profile".into(), profile.map_or(Value::Null, |n| json!(n)));
// A profile whose file could not be read throws, and the document `file.new` made with the
// defaults is put back, with the Recent sizes as they were.
atomically(h, |h| {
@@ -1193,7 +1240,8 @@ fn doc_selection(h: &Host, a: &[Data]) -> Answer {
fn selection_of(h: &Host, uid: u64) -> Answer {
let s = h.session.borrow();
let st = s.documents().iter().find(|d| d.uid == uid).ok_or_else(|| HostError::Error(STALE_DOCUMENT.into()))?;
let ids: Vec<NodeId> = st.selection.objects.iter().copied().filter(|i| st.doc.node(*i).and_then(typename).is_some()).collect();
let ids: Vec<NodeId> =
st.selection.objects.iter().copied().filter(|i| st.doc.node(*i).and_then(typename).is_some()).take(MAX_LISTED + 1).collect();
if ids.is_empty() {
return Ok(Data::Null);
}
+18
View File
@@ -90,6 +90,24 @@ pub(super) fn of_paint(paint: &Paint) -> Data {
}
}
/// Whether assigning the color object `d`, read as `assigned`, leaves the paint `now` as it is: a
/// `NoColor` on no paint, or on an unlinked color either a color equal to it once `store` makes
/// it what the document stores, or the components reading `now` gives (a Gray value read back can
/// stand for an ink amount that no Gray value names exactly).
pub(super) fn unchanged(d: &Data, assigned: Option<Color>, now: &Paint, store: impl FnOnce(Color) -> Color) -> bool {
match (assigned, now) {
(None, Paint::None) => true,
(Some(c), Paint::Solid { color, swatch: None, .. }) => store(c) == *color || shows(d, &of_color(color)),
_ => false,
}
}
/// Whether the color object `d` has the class and every component of `shown`.
fn shows(d: &Data, shown: &Data) -> bool {
let (Data::Object(a), Data::Object(b)) = (d, shown) else { return false };
b.iter().all(|(k, v)| a.iter().any(|(n, w)| n == k && w == v))
}
/// The component `key` of color object `o`, from `min` to `max` (0 when it is left out).
fn component(o: &[(String, Data)], class: &str, key: &str, min: f64, max: f64) -> std::result::Result<f64, HostError> {
match o.iter().find(|(k, _)| k == key).map(|(_, v)| v) {
+4 -8
View File
@@ -55,11 +55,7 @@ fn set_default_color(h: &Host, a: &[Data], fill: bool) -> Answer {
let what = if fill { "defaultFillColor" } else { "defaultStrokeColor" };
let color = colors::assigned(arg(a, 1), what)?;
let now = top_paint(&new_art(h, a)?, fill);
let same = match (&color, &now) {
(None, Paint::None) => true,
(Some(c), Paint::Solid { color, swatch: None, .. }) => c == color,
_ => false,
};
let same = colors::unchanged(arg(a, 1), color, &now, |c| crate::cmd::newart::stored_color(&h.session.borrow(), c));
let paint = match color {
Some(c) => json!({"color": colors::param(&c)}),
None => json!({"none": true}),
@@ -109,7 +105,7 @@ fn set_default_stroke_width(h: &Host, a: &[Data]) -> Answer {
}
this_doc(h, a)?;
let now = h.session.borrow().paint.stroke_width;
set(h, (now - w).abs() < 1e-9, json!({"weight": w}))
set(h, now == w, json!({"weight": w}))
}
fn default_cap(h: &Host, a: &[Data]) -> Answer {
@@ -152,7 +148,7 @@ fn set_default_miter(h: &Host, a: &[Data]) -> Answer {
return Err(HostError::Range("defaultStrokeMiterLimit must be from 1 to 500".into()));
}
let now = stroke_option(h, a, 10.0, |s| s.miter_limit)?;
set(h, (now - v).abs() < 1e-9, json!({"miterLimit": v}))
set(h, now == v, json!({"miterLimit": v}))
}
fn dashes(h: &Host, a: &[Data]) -> std::result::Result<Vec<f64>, HostError> {
@@ -183,7 +179,7 @@ fn set_default_dash_offset(h: &Host, a: &[Data]) -> Answer {
return Err(HostError::Error("defaultStrokeDashOffset needs defaultStrokeDashes first".into()));
}
let now = stroke_option(h, a, 0.0, |s| s.dash.as_ref().map_or(0.0, |d| d.offset))?;
set(h, (now - v).abs() < 1e-9, json!({"dashOffset": v}))
set(h, now == v, json!({"dashOffset": v}))
}
fn scale_factor(h: &Host, a: &[Data]) -> Answer {
+140 -38
View File
@@ -69,7 +69,7 @@ use vectorcraft_tools::params::gradient_params;
use super::{
Answer, Coords, Doc, Item, Link, NOT_FOUND, STALE_ITEM, arg, boolean, class, colors, command, coordinate, doc_of, edit_item, editable, find_doc,
float, frame, get, given, handle_of, id_of, id_parts, item_of, item_rect, later, method, named, num, number, on_doc, pair, point, point_get,
point_method, point_property, property, this_doc, typename_of, whole, with_doc,
point_method, point_property, property, this_doc, whole, with_doc,
};
use crate::{DocState, NodeId, NodeKind};
@@ -140,9 +140,63 @@ fn path_ref(h: &super::Host, item: Item) -> Data {
host_ref("PathItem", &[float(h.run), float(item.doc.uid), high, low])
}
/// How many points a path with the subpaths `subs` has.
fn point_count(subs: &[SubPath]) -> usize {
subs.iter().map(|sp| sp.anchors.len()).sum()
/// The index of the first point of each subpath of `subs`, followed by the number of points.
fn starts(subs: &[SubPath]) -> Vec<usize> {
let mut out = Vec::with_capacity(subs.len() + 1);
let mut n = 0;
for sp in subs {
out.push(n);
n += sp.anchors.len();
}
out.push(n);
out
}
/// The subpath and the place in it of point `i`, given the [`starts`] of a path's subpaths.
fn locate_at(starts: &[usize], i: usize) -> Option<(usize, usize)> {
if i >= *starts.last()? {
return None;
}
let s = starts.partition_point(|first| *first <= i).checked_sub(1)?;
Some((s, i - starts.get(s)?))
}
/// What the [`starts`] that [`super::State`] keeps were counted from: a path's node as its document
/// holds it, by document uid, or the waiting point changes of a path ([`edit_points`]).
pub(super) enum Counted {
Node(u64, Arc<crate::doc::Node>),
Waiting(Item),
}
/// The [`starts`] of the path of `item`, its waiting point changes included. They are kept while
/// the path's node is the same one, or until the waiting changes add or remove points.
fn point_starts(h: &super::Host, item: Item) -> std::result::Result<Rc<Vec<usize>>, HostError> {
let waiting = matches!(&*h.dom.pending.borrow(), Some((w, _)) if same_path(*w, item));
if waiting {
if let Some((Counted::Waiting(k), kept)) = &*h.dom.point_starts.borrow()
&& same_path(*k, item)
{
return Ok(kept.clone());
}
let counted = Rc::new(read_points(h, item, starts)?);
*h.dom.point_starts.borrow_mut() = Some((Counted::Waiting(item), counted.clone()));
return Ok(counted);
}
let node = with_doc(h, item.doc, |_, st| node_arc(&st.doc, item.id).cloned()).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?;
if let Some((Counted::Node(uid, kept_node), kept)) = &*h.dom.point_starts.borrow()
&& *uid == item.doc.uid
&& Arc::ptr_eq(kept_node, &node)
{
return Ok(kept.clone());
}
let counted = Rc::new(starts(&node.path_data().ok_or_else(|| HostError::Type("this is not a PathItem".into()))?.subpaths));
*h.dom.point_starts.borrow_mut() = Some((Counted::Node(item.doc.uid, node), counted.clone()));
Ok(counted)
}
/// How many points the path of `item` has, its waiting point changes included ([`point_starts`]).
fn points_of(h: &super::Host, item: Item) -> std::result::Result<usize, HostError> {
Ok(point_starts(h, item)?.last().copied().unwrap_or(0))
}
/// The subpath and the place in it of point `i`, among the subpaths `subs`.
@@ -180,6 +234,7 @@ fn read_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&[SubPath]) -> T)
/// locked, unless it changes nothing. A path that is aligned to the pixel grid, or is in an object
/// that is, is written at once, so that its points read as the grid snaps them.
fn edit_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&mut Vec<SubPath>) -> T) -> std::result::Result<T, HostError> {
forget_waiting_starts(h);
if let Some((waiting, subs)) = &mut *h.dom.pending.borrow_mut()
&& same_path(*waiting, item)
{
@@ -205,6 +260,33 @@ fn edit_points<T>(h: &super::Host, item: Item, f: impl FnOnce(&mut Vec<SubPath>)
Ok(r)
}
/// Drops the [`starts`] that [`super::State`] keeps of waiting point changes, which a change can
/// make wrong.
fn forget_waiting_starts(h: &super::Host) {
let mut kept = h.dom.point_starts.borrow_mut();
if matches!(&*kept, Some((Counted::Waiting(_), _))) {
*kept = None;
}
}
/// Changes the anchor at index `i` of the path of `item` with `f` ([`edit_points`]). The change
/// adds and removes no points, so the [`starts`] of the path stay kept.
fn edit_anchor(h: &super::Host, item: Item, i: usize, f: impl FnOnce(&mut Anchor)) -> std::result::Result<(), HostError> {
let counted = point_starts(h, item)?;
let at = locate_at(&counted, i);
edit_points(h, item, |subs| {
if let Some((s, j)) = at
&& let Some(an) = subs.get_mut(s).and_then(|sp| sp.anchors.get_mut(j))
{
f(an);
}
})?;
if matches!(&*h.dom.pending.borrow(), Some((w, _)) if same_path(*w, item)) {
*h.dom.point_starts.borrow_mut() = Some((Counted::Waiting(item), counted));
}
Ok(())
}
/// Gives the path of `item` the subpaths `subs` ([`edit_points`]).
fn write_path(h: &super::Host, item: Item, subs: Vec<SubPath>) -> std::result::Result<(), HostError> {
edit_points(h, item, |s| *s = subs)
@@ -214,6 +296,7 @@ fn write_path(h: &super::Host, item: Item, subs: Vec<SubPath>) -> std::result::R
/// the path has those points already.
pub(super) fn flush(h: &super::Host) -> std::result::Result<(), HostError> {
let Some((item, subs)) = h.dom.pending.borrow_mut().take() else { return Ok(()) };
forget_waiting_starts(h);
let same = {
let s = h.session.borrow();
let node = s.documents().iter().find(|d| d.uid == item.doc.uid).and_then(|st| st.doc.node(item.id));
@@ -278,16 +361,13 @@ fn keeping_paint<T>(h: &super::Host, f: impl FnOnce() -> T) -> T {
/// The ids of a document's paths, in the order of its page items.
fn path_items(h: &super::Host, st: &DocState) -> Rc<Vec<NodeId>> {
if let Some((uid, doc, ids)) = &*h.dom.paths.borrow()
&& *uid == st.uid
&& std::sync::Arc::ptr_eq(doc, &st.doc)
{
return ids.clone();
if let Some(ids) = super::kept_list(&h.dom.paths, st) {
return ids;
}
let all = super::page_items(h, st);
let ids: Rc<Vec<NodeId>> =
Rc::new(all.iter().copied().filter(|i| st.doc.node(*i).is_some_and(|n| matches!(n.kind, NodeKind::Path { .. }))).collect());
*h.dom.paths.borrow_mut() = Some((st.uid, st.doc.clone(), ids.clone()));
super::keep_list(&h.dom.paths, st, &ids);
ids
}
@@ -300,6 +380,12 @@ fn items_doc(h: &super::Host, a: &[Data]) -> std::result::Result<Doc, HostError>
doc_of(h, arg(a, 0), "PathItems")
}
/// `typename` of the paths of a document that is still open.
fn items_typename(h: &super::Host, a: &[Data]) -> Answer {
items_doc(h, a)?;
Ok(Data::String("PathItems".into()))
}
fn items_length(h: &super::Host, a: &[Data]) -> Answer {
let doc = items_doc(h, a)?;
Ok(num(float(with_doc(h, doc, |_, st| path_items(h, st).len()) as u64)))
@@ -818,12 +904,7 @@ fn set_color(h: &super::Host, a: &[Data], fill: bool) -> Answer {
let color = colors::assigned(arg(a, 1), if fill { "fillColor" } else { "strokeColor" })?;
let (item, look) = this_look(h, a)?;
let now = if fill { &look.fill } else { &look.stroke };
let same = match (&color, now) {
(None, Paint::None) => true,
(Some(c), Paint::Solid { color, swatch: None, .. }) => c == color,
_ => false,
};
if !same {
if !colors::unchanged(arg(a, 1), color, now, |c| c) {
set_paint(h, item, fill, color)?;
}
Ok(Data::Undefined)
@@ -928,13 +1009,13 @@ pub(super) fn dash_lengths(d: &Data, what: &str) -> std::result::Result<Vec<f64>
Data::Array(list) => list.iter().map(|d| number(d, "each dash length")).collect::<std::result::Result<_, _>>()?,
_ => return Err(HostError::Type(format!("{what} must be an array of lengths"))),
};
if lengths.iter().any(|l| !(0.0..=MAX_STROKE_WIDTH * 1000.0).contains(l)) {
return Err(HostError::Range("each dash length must be from 0 to 1000000 points".into()));
use crate::cmd::newart::DashFault;
match crate::cmd::newart::dash_fault(&lengths) {
None => Ok(lengths),
Some(DashFault::TooMany) => Err(HostError::Range(format!("{what} takes at most {MAX_DASHES} lengths"))),
Some(DashFault::OutOfRange) => Err(HostError::Range("each dash length must be from 0 to 1000000 points".into())),
Some(DashFault::AllZero) => Err(HostError::Range(format!("{what} needs a length that is not 0"))),
}
if !lengths.is_empty() && lengths.iter().all(|l| *l == 0.0) {
return Err(HostError::Range(format!("{what} needs a length that is not 0")));
}
Ok(lengths)
}
/// `strokeDashes = [lengths]`, as [`dash_lengths`] takes them.
@@ -1129,9 +1210,15 @@ fn points_path(h: &super::Host, a: &[Data]) -> std::result::Result<Item, HostErr
path_at(h, *run, *uid, *high, *low)
}
/// `typename` of the points of a path that is still in its document.
fn points_typename(h: &super::Host, a: &[Data]) -> Answer {
points_path(h, a)?;
Ok(Data::String("PathPoints".into()))
}
fn points_length(h: &super::Host, a: &[Data]) -> Answer {
let item = points_path(h, a)?;
read_points(h, item, |subs| num(float(point_count(subs) as u64)))
Ok(num(float(points_of(h, item)? as u64)))
}
fn points_parent(h: &super::Host, a: &[Data]) -> Answer {
@@ -1255,7 +1342,7 @@ fn points_at(h: &super::Host, a: &[Data]) -> Answer {
let item = points_path(h, a)?;
let Data::Number(n) = arg(a, 1) else { return Ok(Data::Undefined) };
let Some(i) = whole(*n).and_then(|i| usize::try_from(i).ok()) else { return Ok(Data::Undefined) };
let n = read_points(h, item, point_count)?;
let n = points_of(h, item)?;
Ok(if i < n { point_ref(h, item, i) } else { Data::Undefined })
}
@@ -1273,18 +1360,33 @@ fn points_index(h: &super::Host, a: &[Data]) -> Answer {
fn points_add(h: &super::Host, a: &[Data]) -> Answer {
let item = points_path(h, a)?;
let origin = with_doc(h, item.doc, |_, st| frame(st).map(|f| f.to_document(h.dom.coords.get(), [0.0, 0.0])));
let (n, last) = read_points(h, item, |subs| (point_count(subs), subs.iter().rev().find_map(|sp| sp.anchors.last()).map(|a| a.p)))?;
let mut counted = point_starts(h, item)?;
let n = counted.last().copied().unwrap_or(0);
if n >= MAX_POINTS {
return Err(HostError::Range(format!("PathPoints.add takes a path to at most {MAX_POINTS} points")));
}
let last = read_points(h, item, |subs| subs.iter().rev().find_map(|sp| sp.anchors.last()).map(|a| a.p))?;
let p = match last {
Some(p) => p,
None => origin?,
};
// The kept starts are dropped, so that `counted` is their only copy and grows in place.
*h.dom.point_starts.borrow_mut() = None;
edit_points(h, item, |subs| match subs.last_mut() {
Some(sp) => sp.anchors.push(Anchor::corner(p)),
None => subs.push(SubPath::new(vec![Anchor::corner(p)], false)),
})?;
if matches!(&*h.dom.pending.borrow(), Some((w, _)) if same_path(*w, item)) {
let grown = Rc::make_mut(&mut counted);
if grown.len() > 1 {
if let Some(total) = grown.last_mut() {
*total += 1;
}
} else {
*grown = vec![0, 1];
}
*h.dom.point_starts.borrow_mut() = Some((Counted::Waiting(item), counted));
}
Ok(point_ref(h, item, n))
}
@@ -1307,8 +1409,7 @@ pub(super) fn this_point(h: &super::Host, a: &[Data]) -> std::result::Result<(It
return Err(HostError::Error(STALE_POINT.into()));
}
let i = whole(*i).and_then(|i| usize::try_from(i).ok()).ok_or_else(|| HostError::Error(STALE_POINT.into()))?;
let n = read_points(h, item, point_count)?;
if i >= n {
if i >= points_of(h, item)? {
return Err(HostError::Error(STALE_POINT.into()));
}
Ok((item, i))
@@ -1319,8 +1420,9 @@ fn read_point(h: &super::Host, a: &[Data], f: impl FnOnce(&super::Frame, Coords,
let (item, i) = this_point(h, a)?;
let c = h.dom.coords.get();
let fr = with_doc(h, item.doc, |_, st| frame(st))?;
let at = locate_at(&point_starts(h, item)?, i);
read_points(h, item, |subs| {
let anchor = locate(subs, i).and_then(|(s, j)| subs.get(s).and_then(|sp| sp.anchors.get(j)));
let anchor = at.and_then(|(s, j)| subs.get(s).and_then(|sp| sp.anchors.get(j)));
anchor.map(|an| f(&fr, c, an)).ok_or_else(|| HostError::Error(STALE_POINT.into()))
})?
}
@@ -1329,13 +1431,7 @@ fn read_point(h: &super::Host, a: &[Data], f: impl FnOnce(&super::Frame, Coords,
/// coordinates (for a point property) or the value itself.
fn edit_point(h: &super::Host, a: &[Data], f: impl FnOnce(&mut Anchor)) -> Answer {
let (item, i) = this_point(h, a)?;
edit_points(h, item, |subs| {
if let Some((s, j)) = locate(subs, i)
&& let Some(an) = subs.get_mut(s).and_then(|sp| sp.anchors.get_mut(j))
{
f(an);
}
})?;
edit_anchor(h, item, i, f)?;
Ok(Data::Undefined)
}
@@ -1392,6 +1488,12 @@ fn pt_parent(h: &super::Host, a: &[Data]) -> Answer {
Ok(path_ref(h, item))
}
/// `typename` of a point that is still on its path.
fn pt_typename(h: &super::Host, a: &[Data]) -> Answer {
this_point(h, a)?;
Ok(Data::String("PathPoint".into()))
}
/// Whether a group or compound path that holds the path `id` is selected, which selects the path
/// as a whole whatever the path's own selection is.
fn held_selected(d: &crate::Document, sel: &crate::doc::Selection, id: NodeId) -> bool {
@@ -1573,7 +1675,7 @@ pub(super) fn classes(l: &Link) -> Vec<HostClass> {
"PathItems",
None,
named(vec![
("typename", typename_of("PathItems")),
("typename", get(l, items_typename)),
("length", get(l, items_length)),
("parent", get(l, items_parent)),
("index", method(l, items_index)),
@@ -1592,7 +1694,7 @@ pub(super) fn classes(l: &Link) -> Vec<HostClass> {
"PathPoints",
None,
named(vec![
("typename", typename_of("PathPoints")),
("typename", point_get(l, points_typename)),
("length", point_get(l, points_length)),
("parent", point_get(l, points_parent)),
("index", point_method(l, points_index)),
@@ -1605,7 +1707,7 @@ pub(super) fn classes(l: &Link) -> Vec<HostClass> {
"PathPoint",
None,
named(vec![
("typename", typename_of("PathPoint")),
("typename", point_get(l, pt_typename)),
("parent", point_get(l, pt_parent)),
("anchor", point_property(l, pt_anchor, pt_set_anchor)),
("leftDirection", point_property(l, pt_left, pt_set_left)),
+11
View File
@@ -2227,6 +2227,17 @@ impl Session {
RunError { kind: RunErrorKind::Limit(kind), message: format!("limit reached: {kind:?}"), line: 0, column: 0, authored: false };
return Some(self.script_failed(job, &e));
}
// One more allowance may still leave the growth past it: the person is asked again
// while they may be, and past that the run ends unkept.
if let Err(HostError::Abort(message)) = job.host.charge_growth(0, 0) {
let e = RunError { kind: RunErrorKind::Limit(LimitKind::Host), message, line: 0, column: 0, authored: false };
return Some(self.script_failed(job, &e));
}
if job.host.waiting.get() {
JOBS.with(|jobs| jobs.borrow_mut().insert(key.id, job));
self.script_key = Some(key);
return None;
}
return Some(self.script_ended(job));
}
// A stop while a dialog waits ends the run there; the interpreter cannot go on from the call.