diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/eval/array.rs | 12 | ||||
| -rw-r--r-- | crates/typst/src/eval/methods.rs | 5 |
2 files changed, 14 insertions, 3 deletions
diff --git a/crates/typst/src/eval/array.rs b/crates/typst/src/eval/array.rs index 5d5fdcdb..86c41ff6 100644 --- a/crates/typst/src/eval/array.rs +++ b/crates/typst/src/eval/array.rs @@ -392,10 +392,18 @@ impl Array { } /// Enumerate all items in the array. - pub fn enumerate(&self) -> Self { + pub fn enumerate(&self, start: i64) -> StrResult<Self> { self.iter() .enumerate() - .map(|(i, value)| array![i, value.clone()].into_value()) + .map(|(i, value)| { + Ok(array![ + start + .checked_add_unsigned(i as u64) + .ok_or_else(|| "array index is too large".to_string())?, + value.clone() + ] + .into_value()) + }) .collect() } diff --git a/crates/typst/src/eval/methods.rs b/crates/typst/src/eval/methods.rs index bf47b7aa..6a846f52 100644 --- a/crates/typst/src/eval/methods.rs +++ b/crates/typst/src/eval/methods.rs @@ -146,7 +146,10 @@ pub fn call( } "sorted" => array.sorted(vm, span, args.named("key")?)?.into_value(), "zip" => array.zip(args.expect("other")?).into_value(), - "enumerate" => array.enumerate().into_value(), + "enumerate" => array + .enumerate(args.named("start")?.unwrap_or(0)) + .at(span)? + .into_value(), "dedup" => array.dedup(vm, args.named("key")?)?.into_value(), _ => return missing(), }, |
