DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Threading: Shift-click autoflow from a frame on a parent spread is an error
aiongg4fbd86733733
diff --git a/crates/engine/src/cmd/place_text.rs b/crates/engine/src/cmd/place_text.rsindex 97917ee3b..b93f2b9ff 100644--- a/crates/engine/src/cmd/place_text.rs+++ b/crates/engine/src/cmd/place_text.rs@@ -124,7 +124,12 @@ fn fit(d: &Document, sid: StoryId) -> (Option<usize>, usize, usize) {}/// Thread new frames on new pages (margin rectangles) until the story fits. Returns pages added.+/// A story on a parent spread doesn't autoflow: its frames thread only on that parent.pub(crate) fn autoflow(d: &mut Document, sid: StoryId, max_pages: usize) -> Result<usize> {+ let last = d.story(sid).and_then(|s| s.frames.last().copied()).ok_or_else(|| bad("file.place", "the story has no frame"))?;+ if !matches!(d.find(last).map(|l| l.spread), Some(SpreadRef::Doc(_))) {+ return Err(bad("file.place", "autoflow works only from a frame on a document page"));+ }let mut added = 0;loop {let (overset, held, full) = fit(d, sid);diff --git a/crates/engine/src/cmd/thread.rs b/crates/engine/src/cmd/thread.rsindex ff360e00a..71c877bf8 100644--- a/crates/engine/src/cmd/thread.rs+++ b/crates/engine/src/cmd/thread.rs@@ -280,6 +280,24 @@ mod tests {assert_eq!(s.doc().unwrap().doc.page_count(), 2);}+ #[test]+ fn autoflow_from_a_parent_frame_is_an_error() {+ let mut s = session();+ let parent = json!({"kind": "parent", "index": 0});+ let r = s.execute(+ "frame.create",+ &json!({"rect": [72, 72, 300, 200], "content": "text", "text": LONG.repeat(300), "caret": false, "spread": parent}),+ );+ let a = r.unwrap()["id"].as_u64().unwrap();+ let undo = s.doc().unwrap().history.undo.len();+ let doc = s.doc().unwrap().doc.clone();+ let e = s.execute("text.thread", &json!({"from": a, "rect": [72, 300, 300, 700], "spread": parent, "autoflow": true})).unwrap_err();+ assert!(e.to_string().contains("document page"), "{e}");+ assert_eq!(s.doc().unwrap().history.undo.len(), undo);+ assert_eq!(*s.doc().unwrap().doc, *doc);+ assert_eq!(s.doc().unwrap().doc.page_count(), 2);+ }+#[test]fn unthread_after_and_before() {let mut s = session();