DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Index: next-paragraph ranges saturate and read the paragraph list with get
Brandon Thomas50161d0d42c6
diff --git a/crates/engine/src/cmd/index.rs b/crates/engine/src/cmd/index.rsindex 6ca36ee7d..38a6bc49d 100644--- a/crates/engine/src/cmd/index.rs+++ b/crates/engine/src/cmd/index.rs@@ -105,8 +105,9 @@ fn resolve(s: &Session, d: &Document, skip: Option<StoryId>) -> Vec<(StoryId, usIndexRange::ToEndOfStory => page(st.len().saturating_sub(1)),IndexRange::NextParagraphs(n) => {let ranges = st.para_ranges();- let pi = (st.para_at(pos) + *n as usize).min(ranges.len() - 1);- page(ranges[pi].end.saturating_sub(1).max(ranges[pi].start))+ let n = usize::try_from(*n).unwrap_or(usize::MAX);+ let pi = st.para_at(pos).saturating_add(n).min(ranges.len().saturating_sub(1));+ ranges.get(pi).and_then(|r| page(r.end.saturating_sub(1).max(r.start)))}_ => start,};