Scripts: closing a path with no points throws

PathItem.closed = true on a path with no points had no subpath to store
the value in, so the assignment reported success while closed still
read false. It now throws "Cannot close a path that has no points".
This commit is contained in:
dotCooCoo committed 2026-11-28 03:21:05 -08:00
1 parent 011f477546
commit f6619ed732
3 files changed
+14

No files matched your search

+4
View File
@@ -760,6 +760,10 @@ fn path_closed(h: &super::Host, a: &[Data]) -> Answer {
fn path_set_closed(h: &super::Host, a: &[Data]) -> Answer {
let closed = boolean(arg(a, 1), "closed")?;
let item = this_path(h, a)?;
// A path with no points has no subpath to keep the value in.
if closed && read_points(h, item, |subs| subs.is_empty())? {
return Err(HostError::Error("Cannot close a path that has no points".into()));
}
edit_points_keeping(h, item, true, |subs| subs.iter_mut().for_each(|sp| sp.closed = closed))?;
Ok(Data::Undefined)
}
@@ -193,6 +193,15 @@ fn opening_a_path_deselects_its_closing_segment() {
assert!(sel.objects.contains(&a));
}
#[test]
fn closing_a_path_without_points_throws() {
let (mut s, _, _) = doc();
let e = failure(&mut s, "var p = app.activeDocument.pathItems.add(); p.closed = true;");
assert!(e.contains("Cannot close a path that has no points"), "{e}");
// Opening it stores nothing and is allowed.
log(&mut s, "var p = app.activeDocument.pathItems.add(); p.closed = false;");
}
#[test]
fn set_anchors_with_other_anchor_counts_deselects_the_paths_anchors() {
let (mut s, a, b) = doc();
+1
View File
@@ -3001,6 +3001,7 @@ other files through `$`:
`setEntirePath`, `pathPoints` and each `PathPoint`) are written together with one `path.setAnchors` before the
script uses any other member or command, or the points of another path, and when the script ends; a path aligned
to the pixel grid, or in an object that is, is written at each change, so its points read as the grid snaps them.
Setting `closed` to true on a path with no points throws `Cannot close a path that has no points`.
Writing changes that added, removed or replaced points deselects the path's direct-selected anchors, even when the
path ends with as many points as before; changes that only move points or handles, change a point's type or set
`closed` keep them selected.