mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 05:22:58 -05:00
Scripts: stale layers and artboards throw their stale error from index()
layers.index(n) and artboards.index(n) returned Not found for a negative or fractional number before checking whether the collection was stale, so a script holding a stale collection got the wrong error. Both now check the collection first, as the art collections' index() does.
This commit is contained in:
1 parent
3368ac519c
commit
a53165fa85
3 files changed
+28
-5
No files matched your search
@@ -634,8 +634,12 @@ fn layers_by_name(h: &Host, a: &[Data]) -> Answer {
|
||||
fn layers_index(h: &Host, a: &[Data]) -> Answer {
|
||||
match arg(a, 1) {
|
||||
Data::String(_) => layers_by_name(h, a),
|
||||
// A number is a position here, never a name ([`layers_at`]).
|
||||
Data::Number(n) if super::position(*n).is_none() => Err(HostError::Error(NOT_FOUND.into())),
|
||||
// A number is a position here, never a name ([`layers_at`]). A stale collection throws its
|
||||
// stale error first.
|
||||
Data::Number(n) if super::position(*n).is_none() => {
|
||||
layers_scope(h, arg(a, 0))?;
|
||||
Err(HostError::Error(NOT_FOUND.into()))
|
||||
}
|
||||
Data::Number(_) => match layers_at(h, a)? {
|
||||
Data::Undefined => Err(HostError::Error(NOT_FOUND.into())),
|
||||
d => Ok(d),
|
||||
@@ -1479,8 +1483,12 @@ fn boards_by_name(h: &Host, a: &[Data]) -> Answer {
|
||||
fn boards_index(h: &Host, a: &[Data]) -> Answer {
|
||||
match arg(a, 1) {
|
||||
Data::String(_) => boards_by_name(h, a),
|
||||
// A number is a position here, never a name ([`boards_at`]).
|
||||
Data::Number(n) if super::position(*n).is_none() => Err(HostError::Error(NOT_FOUND.into())),
|
||||
// A number is a position here, never a name ([`boards_at`]). A stale collection throws its
|
||||
// stale error first.
|
||||
Data::Number(n) if super::position(*n).is_none() => {
|
||||
boards_doc(h, a)?;
|
||||
Err(HostError::Error(NOT_FOUND.into()))
|
||||
}
|
||||
Data::Number(_) => match boards_at(h, a)? {
|
||||
Data::Undefined => Err(HostError::Error(NOT_FOUND.into())),
|
||||
d => Ok(d),
|
||||
|
||||
@@ -4899,6 +4899,20 @@ fn a_stale_containers_list_throws_its_stale_error_for_any_index() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A stale `layers` or `artboards` collection's `index(n)` throws the stale error for every
|
||||
/// number, a negative or fractional one included, as the art collections do.
|
||||
#[test]
|
||||
fn stale_layers_and_artboards_throw_their_stale_error_for_any_index() {
|
||||
let (mut s, ..) = doc();
|
||||
run(&mut s, "#targetengine keep\nvar d = app.activeDocument, L = d.layers, A = d.artboards;").unwrap();
|
||||
for list in ["L", "A"] {
|
||||
for n in ["-1", "1.5", "0"] {
|
||||
let e = failure(&mut s, &format!("#targetengine keep\n{list}.index({n});"));
|
||||
assert!(e.contains("Stale document"), "{list}.index({n}): {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `removeAll()` on a clip group releases its mask, so an object added to the group afterwards is
|
||||
/// not its clipping path; the run's one undo step puts everything back.
|
||||
#[test]
|
||||
|
||||
+2
-1
@@ -3434,7 +3434,8 @@ through `$`:
|
||||
chosen. The chosen artboard stays active when another is inserted before it, even if it was already the active
|
||||
one. `insert`, `remove` and `setActiveArtboardIndex` throw a `RangeError` for an index outside the list. Reading
|
||||
an index past the last artboard gives `undefined` from `artboards[i]` and throws `Not found` from
|
||||
`artboards.index(i)`. A layer that was deleted throws `Stale layer`, and an artboard that was deleted throws
|
||||
`artboards.index(i)`. `layers.index(n)` and `artboards.index(n)` on a collection whose document or layer is stale
|
||||
throw its stale error for any number, a negative or fractional one included, before `Not found`. A layer that was deleted throws `Stale layer`, and an artboard that was deleted throws
|
||||
`Stale artboard`. `Layer.blendingMode`, `artworkKnockout` and `sliced` and `GroupItems.createFromFile` throw an
|
||||
error that says they are not available yet. `GroupItems.createFromFile` on a collection whose document, layer or
|
||||
group was deleted throws `Stale page item` or `Stale document` first.
|
||||
|
||||
Reference in new issue
Block a user