Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into codex/pages-panel-duplicate

moppeeer15fccae6b819
diff --cc ROADMAP.md
index cf4d92cff,c60a04107..55bdd15ee
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -129,7 -128,13 +128,14 @@@ list) · [roadmap.md](docs/roadmap.md)
Newest first.
+- **2026-10-14** · Pages panel: Alt-drag copies a page, a page dropped on Create new page is duplicated at the end, Edit page size offers the presets and Custom Page Size…; duplicated pages keep their own size, rule and guides; thumbnails of pages of their own size stay in their rows. No readiness percentage change.
+ - **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load
+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or
+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the
+ frame just added; click the linked frame or double-click a port to break the thread.
+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers
+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No
+ readiness percentage change.
- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.
- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.
- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.
diff --cc crates/engine/src/tests.rs
index f896ab3cd,9d6308983..0e7a011f7
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -570,28 -570,102 +570,128 @@@ fn commands_take_non_object_params_with
}
}
+#[test]
+fn duplicating_a_page_keeps_its_own_size_rule_guides_and_objects() {
+ // Chris Cicchino's Page Tool video (2:06): the letterhead page is duplicated, then resized.
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 252, "height": 144, "facingPages": false})).unwrap();
+ s.execute("layout.pages.insert", &json!({"count": 1})).unwrap();
+ s.execute("layout.pageSize", &json!({"pages": [2], "width": 612, "height": 792})).unwrap();
+ s.execute("liquid.pageRule", &json!({"rule": "scale", "pages": [2]})).unwrap();
+ s.execute("guide.add", &json!({"spread": 1, "page": 0, "orientation": "vertical", "position": 300})).unwrap();
+ s.execute("frame.create", &json!({"spread": 1, "rect": [100, 100, 200, 200]})).unwrap();
+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 1})).unwrap();
+ assert_eq!(r["page"], 2);
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(2).unwrap();
+ let pg = &d.spreads[si].pages[pi];
+ assert_eq!((pg.width, pg.height, pg.liquid), (612.0, 792.0, designcraft_doc::LiquidRule::Scale));
+ assert_eq!(pg.guides.len(), 1);
+ assert_eq!(d.spreads[si].items.len(), 1);
+ // At the end of the document (the New Page button): the business card, not the last page's size.
+ let r = s.execute("layout.pages.duplicateSpread", &json!({"spread": 0, "atEnd": true})).unwrap();
+ assert_eq!(r["page"], 3);
+ let d = s.doc().unwrap().doc.clone();
+ let (si, pi) = d.page_loc(3).unwrap();
+ assert_eq!((d.spreads[si].pages[pi].width, d.spreads[si].pages[pi].height), (252.0, 144.0));
+}
++
+ /// Load the text from a frame's out port with the Selection tool and click on the pasteboard:
+ /// a new frame is threaded there and the overset text flows into it.
+ #[test]
+ fn threading_with_the_loaded_text_cursor_on_the_sample() {
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let mut s = Session::new();
+ s.execute("file.newSample", &json!({})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ let (sid, first) = d.stories.values().find(|st| st.frames.len() >= 2).map(|st| (st.id, st.frames[0])).expect("a threaded story");
+ // Break the thread so the first frame is overset, and select it.
+ s.execute("text.unthread", &json!({"frame": first.0})).unwrap();
+ assert!(s.cache.get(&s.doc().unwrap().doc, sid, None).is_overset());
+ s.execute("selection.set", &json!({"ids": [first.0]})).unwrap();
+ s.set_tool("selection");
+ let v = ViewInfo::at_zoom(1.0);
+ let layout = s.layout();
+ let port = designcraft_tools::thread::port_center(&s.doc().unwrap().doc, &layout, first, true, v.zoom).unwrap();
+ let ev = |k, p: designcraft_geom::Point| PointerEvent::new(k, p.x, p.y);
+ s.pointer(&ev(PointerKind::Down, port), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, port), v).unwrap();
+ assert_eq!(s.cursor(port + designcraft_geom::Vec2::new(-2000.0, 0.0), Default::default(), v), designcraft_tools::Cursor::LoadedText);
+ // On the pasteboard left of the first spread.
+ let b = layout.slots[0].bounds;
+ let at = designcraft_geom::Point::new(b.x0 - 300.0, b.y0 + 100.0);
+ let undo = s.doc().unwrap().history.undo.len();
+ s.pointer(&ev(PointerKind::Down, at), v).unwrap();
+ s.pointer(&ev(PointerKind::Up, at), v).unwrap();
+ let st = s.doc().unwrap();
+ assert_eq!(st.history.undo.len(), undo + 1, "one undo step");
+ let frames = st.doc.story(sid).unwrap().frames.clone();
+ assert_eq!(frames.len(), 2);
+ let new = frames[1];
+ assert_eq!(st.selection.items, [new]);
+ let cs = s.cache.get(&s.doc().unwrap().doc, sid, None);
+ assert!(cs.frames.iter().any(|f| f.frame == new && !f.range.is_empty()), "the text flows into the new frame");
+ let nb = s.doc().unwrap().doc.item(new).unwrap().bounds();
+ assert!((nb.y0 - layout.to_spread(designcraft_doc::SpreadRef::Doc(0), at).y).abs() < 1e-6, "{nb:?}");
+ }
+
+ /// Drag a selection handle of item 0 on spread 0 from the edge point `at` by `by` (canvas units).
+ fn drag_handle(s: &mut Session, at: designcraft_geom::Point, by: designcraft_geom::Vec2, v: ViewInfo) {
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let p = s.layout().to_canvas(designcraft_doc::SpreadRef::Doc(0), at);
+ s.pointer(&PointerEvent::new(PointerKind::Down, p.x, p.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, p.x + by.x / 2.0, p.y + by.y / 2.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, p.x + by.x, p.y + by.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, p.x + by.x, p.y + by.y), v).unwrap();
+ }
+
+ #[test]
+ fn text_frame_resize_snaps_to_the_margins() {
+ use designcraft_geom::{Point, Vec2};
+ for zoom in [1.0, 0.5] {
+ let mut s = Session::new();
+ s.execute("file.newSample", &json!({})).unwrap();
+ let margin = s.doc().unwrap().doc.spreads[0].pages[0].margin_rect();
+ let (x0, y0) = (margin.x0 + 40.0, margin.y0 + 40.0);
+ s.execute("frame.create", &json!({"rect": [x0, y0, x0 + 200.0, y0 + 200.0], "content": "text"})).unwrap();
+ s.set_tool("selection");
+ let v = ViewInfo::at_zoom(zoom);
+ let b0 = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ // Right handle to 1.5 pt short of the right margin.
+ drag_handle(&mut s, Point::new(b0.x1, b0.center().y), Vec2::new(margin.x1 - 1.5 - b0.x1, 0.0), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.x1 - margin.x1).abs() < 1e-6, "zoom {zoom}: right edge {} not on the margin {}", b.x1, margin.x1);
+ // Bottom handle to 1.5 pt past the bottom margin.
+ drag_handle(&mut s, Point::new(b.center().x, b.y1), Vec2::new(0.0, margin.y1 + 1.5 - b.y1), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.y1 - margin.y1).abs() < 1e-6, "zoom {zoom}: bottom edge {} not on the margin {}", b.y1, margin.y1);
+ // Top-left corner handle onto the top and left margins.
+ drag_handle(&mut s, Point::new(b.x0, b.y0), Vec2::new(margin.x0 + 1.0 - b.x0, margin.y0 - 1.0 - b.y0), v);
+ let b = s.doc().unwrap().doc.spreads[0].items.last().unwrap().bounds();
+ assert!((b.x0 - margin.x0).abs() < 1e-6 && (b.y0 - margin.y0).abs() < 1e-6, "zoom {zoom}: corner {b:?} not on the margins {margin:?}");
+ }
+ }
+
+ #[test]
+ fn type_tool_frames_snap_to_the_margins() {
+ use designcraft_geom::Point;
+ use designcraft_tools::{PointerEvent, PointerKind};
+ let mut s = session();
+ let margin = s.doc().unwrap().doc.spreads[0].pages[0].margin_rect();
+ s.set_tool("type");
+ let v = ViewInfo::at_zoom(1.0);
+ let c = |s: &Session, x: f64, y: f64| s.layout().to_canvas(designcraft_doc::SpreadRef::Doc(0), Point::new(x, y));
+ // From 1.5 pt off the top-left margin corner to 1.5 pt off the right margin.
+ let a = c(&s, margin.x0 + 1.5, margin.y0 + 1.5);
+ let b = c(&s, margin.x1 - 1.5, margin.y0 + 101.5);
+ let before = s.doc().unwrap().doc.spreads[0].items.len();
+ s.pointer(&PointerEvent::new(PointerKind::Down, a.x, a.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, (a.x + b.x) / 2.0, b.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, b.x, b.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, b.x, b.y), v).unwrap();
+ let items = &s.doc().unwrap().doc.spreads[0].items;
+ assert_eq!(items.len(), before + 1, "a frame was drawn");
+ let r = items.last().unwrap().bounds();
+ assert!((r.x0 - margin.x0).abs() < 1e-6 && (r.y0 - margin.y0).abs() < 1e-6, "press point {r:?} vs {margin:?}");
+ assert!((r.x1 - margin.x1).abs() < 1e-6, "right edge {} vs {}", r.x1, margin.x1);
+ }