DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge branch 'pr/647' into batch1
Brandon Thomasa390905beb03
diff --cc ROADMAP.mdindex 4161fa926,35bc92d16..1e0fcdc21--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,13 -129,8 +129,15 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **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.+- **2026-10-12** · Book numbering and style updates prepare every chapter before saving. Only closed native chapters are changed; imported IDML remains a read-only style/PDF source. If a later disk write fails, the error names the completed chapters; the batch is not a whole-book transaction. No readiness percentage change.+- **2026-10-12** · Desktop write callbacks and CLI raster exports use the atomic writer too; open readers retain the original bytes, while private Unix modes and symlink targets survive replacement. Permanent tests cover both actual callers. No readiness percentage change.+- **2026-10-12** · Save As, library edits and book collection edits persist prospective values before changing live state; failed writes preserve the document and existing collections. Save a Copy rebases data-source paths for its destination without changing the open document. No readiness percentage change.+- **2026-10-12** · The Pen tool continues an open path from either end point, as in InDesign: the cursor shows it over an end point, a click there carries on drawing that path, a drag first reshapes the end point's direction lines, and the other end closes it. Object › Paths › Reverse Path (`path.reverse`); `path.setAnchor`; `path.appendAnchor` and `path.close` take a subpath. No readiness percentage change.+ - **2026-10-12** · Editing type on a path: the Type tool clicks, drags and double-clicks along the curve (the character under the pointer, not one on the straightened line), a click on the letters themselves hits the frame, and the caret and highlight bend with the path. No readiness percentage change.+ - **2026-10-12** · Type on a path has start and end brackets, as in InDesign: selected path type shows them across the path, and dragging either with the Selection or Direct Selection tool moves where the text starts or ends (text past the end bracket is overset). `type.pathOptions {end}`; IDML reads and writes EndBracket. No readiness percentage change.- **2026-10-12** · Window close and application/menu Quit ask about unsaved documents; later Cancel keeps every tab open, including earlier Don't Save choices. Approvals are rechecked after edits. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.- **2026-10-12** · Each running app keeps recovery data in its own locked folder; current folder and lock ownership are checked before writes and cleanup. Failed isolation disables recovery with a warning instead of sharing document IDs. No readiness percentage change.- **2026-10-12** · Native engine saves and exports replace files atomically; failed writes retain the original, private staging preserves Unix permissions, and valid long filenames work. Desktop Services and CLI raster exports remain separate follow-ups. No readiness percentage change.diff --cc crates/tools/src/lib.rsindex 87bece8b4,02b790d55..f3de390a4--- a/crates/tools/src/lib.rs+++ b/crates/tools/src/lib.rs@@@ -340,8 -335,8 +340,10 @@@ pub enum CursorResizeNeSw,Rotate,Pen,+ /// The Pen over an open path's end point: a click continues the path.+ PenContinue,+ /// Over a type-on-a-path bracket: dragging it moves where the text starts or ends.+ PathBracket,Text,Hand,HandGrab,diff --cc crates/tools/src/tests.rsindex f8f58c7d3,e39f8d4ee..e8fe51478--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@@ -706,61 -706,50 +706,109 @@@ fn pen_click_snaps_to_a_guide()assert!((x - 100.0).abs() < 1e-6, "anchor x {x}");}+#[test]+fn pen_continues_an_open_path_from_either_end_point() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = ItemId(d.alloc());+ let anchors = vec![+ designcraft_geom::Anchor::corner(Point::new(100.0, 100.0)),+ designcraft_geom::Anchor {+ p: Point::new(200.0, 100.0),+ h_in: Point::new(170.0, 80.0),+ h_out: Point::new(230.0, 120.0),+ kind: designcraft_geom::AnchorKind::Smooth,+ },+ ];+ let mut it = Item::new(id, lid, Shape::Path, designcraft_geom::PathData::single(designcraft_geom::SubPath::new(anchors, false)));+ it.stroke = Stroke::default();+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let off = l.xf(SpreadRef::Doc(0)).translation();+ let at = |x: f64, y: f64| (x + off.x, y + off.y);+ let ev = |k: PointerKind, (x, y): (f64, f64)| PointerEvent::new(k, x, y);+ let mut t = create("pen");+ // The cursor says the end point continues the path; elsewhere it's the plain pen.+ assert_eq!(t.cursor(&cx, Point::new(at(200.0, 100.0).0, at(200.0, 100.0).1), Mods::default()), Cursor::PenContinue);+ assert_eq!(t.cursor(&cx, Point::new(at(150.0, 300.0).0, at(150.0, 300.0).1), Mods::default()), Cursor::Pen);+ // Clicking the last anchor adds nothing yet; the next click appends to that path.+ assert!(t.pointer(&cx, &ev(PointerKind::Down, at(200.0, 100.0))).is_empty());+ assert!(t.pointer(&cx, &ev(PointerKind::Up, at(200.0, 100.0))).is_empty(), "a click on the end point changes nothing");+ t.pointer(&cx, &ev(PointerKind::Down, at(300.0, 200.0)));+ let a = t.pointer(&cx, &ev(PointerKind::Up, at(300.0, 200.0)));+ let [Action::Exec(cmd, p)] = a.as_slice() else { panic!("{a:?}") };+ assert_eq!((cmd.as_str(), p["id"].as_u64(), p["subpath"].as_u64()), ("path.appendAnchor", Some(id.0), Some(0)));+ assert_eq!((p["anchor"]["p"][0].as_f64(), p["anchor"]["p"][1].as_f64()), (Some(300.0), Some(200.0)));+ // Clicking the first anchor of the other end closes it.+ let a = t.pointer(&cx, &ev(PointerKind::Down, at(100.0, 100.0)));+ assert_eq!(a, vec![Action::Exec("path.close".into(), serde_json::json!({"id": id.0, "subpath": 0}))]);+ assert!(t.pointer(&cx, &ev(PointerKind::Up, at(100.0, 100.0))).is_empty());+ // From the first anchor, the path is reversed first; a drag there sets its direction lines.+ let mut t = create("pen");+ let a = t.pointer(&cx, &ev(PointerKind::Down, at(100.0, 100.0)));+ assert_eq!(a, vec![Action::Exec("path.reverse".into(), serde_json::json!({"ids": [id.0], "subpath": 0}))]);+ t.pointer(&cx, &ev(PointerKind::Drag, at(80.0, 140.0)));+ let a = t.pointer(&cx, &ev(PointerKind::Up, at(80.0, 140.0)));+ assert_eq!(+ a,+ vec![Action::Exec(+ "path.setAnchor".into(),+ serde_json::json!({"id": id.0, "subpath": 0, "anchor": "last", "in": [120.0, 60.0], "out": [80.0, 140.0]})+ )]+ );+ // Closed paths and locked paths aren't continued.+ let mut d2 = d.clone();+ d2.item_mut(id).unwrap().locked = true;+ let cx = ctx(&d2, &s, &c, &l);+ let t = create("pen");+ assert_eq!(t.cursor(&cx, Point::new(at(200.0, 100.0).0, at(200.0, 100.0).1), Mods::default()), Cursor::Pen);+}+++ #[test]+ fn the_selection_tool_drags_a_path_type_bracket_along_its_path() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let id = ItemId(d.alloc());+ let line = designcraft_geom::PathData::single(designcraft_geom::SubPath::new(+ vec![designcraft_geom::Anchor::corner(Point::new(100.0, 300.0)), designcraft_geom::Anchor::corner(Point::new(500.0, 300.0))],+ false,+ ));+ let mut it = Item::new(id, lid, Shape::GraphicLine, line);+ let sid = designcraft_doc::StoryId(d.alloc());+ let mut tf = designcraft_doc::TextFrame { story: sid, options: Default::default() };+ tf.options.path = Some(designcraft_doc::PathType { start: 40.0, end: Some(300.0), ..Default::default() });+ it.content = designcraft_doc::Content::Text(tf);+ let mut st = designcraft_doc::Story::with_text(sid, "On the line", Default::default());+ st.frames = vec![id];+ d.stories.insert(sid, Arc::new(st));+ d.insert_item(SpreadRef::Doc(0), it, None).unwrap();+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let off = l.xf(SpreadRef::Doc(0)).translation();+ let at = |x: f64, y: f64| Point::new(x + off.x, y + off.y);+ let ev = |k: PointerKind, p: Point| PointerEvent::new(k, p.x, p.y);+ // Not selected: no brackets.+ let none = Selection::default();+ assert!(create("selection").overlays(&ctx(&d, &none, &c, &l)).is_empty());+ let s = Selection { items: vec![id], ..Default::default() };+ let cx = ctx(&d, &s, &c, &l);+ let mut t = create("selection");+ // Both brackets drawn across the path at 140 and 400 (a line and a tick each).+ let o = t.overlays(&cx);+ let xs: Vec<f64> = o.iter().filter_map(|o| if let Overlay::Line { a, b, .. } = o { (a.x == b.x).then_some(a.x - off.x) } else { None }).collect();+ assert_eq!(xs, [140.0, 400.0], "{o:?}");+ assert_eq!(t.cursor(&cx, at(140.0, 300.0), Mods::default()), Cursor::PathBracket);+ assert_ne!(t.cursor(&cx, at(250.0, 300.0), Mods::default()), Cursor::PathBracket);+ // Drag the start bracket: its distance along the path follows the pointer, off the path too.+ assert_eq!(t.pointer(&cx, &ev(PointerKind::Down, at(140.0, 301.0))), vec![Action::Begin("Move Bracket".into())]);+ let a = t.pointer(&cx, &ev(PointerKind::Drag, at(220.0, 330.0)));+ let [Action::Preview(cmd, p)] = a.as_slice() else { panic!("{a:?}") };+ assert_eq!((cmd.as_str(), p["id"].as_u64()), ("type.pathOptions", Some(id.0)));+ assert!((p["start"].as_f64().unwrap() - 120.0).abs() < 1e-6, "{p}");+ assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, at(220.0, 330.0))), vec![Action::Commit]);+ // The end bracket.+ t.pointer(&cx, &ev(PointerKind::Down, at(400.0, 300.0)));+ let a = t.pointer(&cx, &ev(PointerKind::Drag, at(450.0, 290.0)));+ let [Action::Preview(_, p)] = a.as_slice() else { panic!("{a:?}") };+ assert!((p["end"].as_f64().unwrap() - 350.0).abs() < 1e-6, "{p}");+ }diff --cc crates/ui-egui/src/canvas.rsindex 71cdd1754,5bc9146ed..077ae2944--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -352,7 -352,8 +352,8 @@@ fn cursor_icon(c: Cursor) -> egui::CursCursor::ResizeNwSe => C::ResizeNwSe,Cursor::ResizeNeSw => C::ResizeNeSw,Cursor::Rotate => C::Alias,- Cursor::Pen => C::Crosshair,+ Cursor::Pen | Cursor::PenContinue => C::Crosshair,+ Cursor::PathBracket => C::ResizeColumn,Cursor::Text => C::Text,Cursor::Hand => C::Grab,Cursor::HandGrab => C::Grabbing,