DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge origin/main into codex/content-handles
moppeeer0c8d5e96df94
diff --cc ROADMAP.mdindex 5c0619255,c60a04107..c3d0a6a84--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -129,7 -128,13 +128,14 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+- **2026-10-13** · A selected placed graphic shows its own brown bounding box with handles: dragging one resizes the graphic inside its frame (Shift keeps proportions, Alt from the centre) and leaves the frame as it is; `transform.set` takes the graphic's new spread `bounds`. Builds on #415 and #550. 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.rsindex 3da265f21,9d6308983..6a3005758--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -570,37 -570,102 +570,137 @@@ fn commands_take_non_object_params_with}}+#[test]+fn direct_selection_drag_and_arrow_keys_move_placed_content() {+ use designcraft_tools::{Mods, PointerEvent, PointerKind, SnapView, ToolKey};+ let mut s = session();+ let png = designcraft_render::Rendered { width: 40, height: 20, pixels: vec![200; 40 * 20 * 4] }.to_png();+ let f = s.execute("frame.create", &json!({"rect": [100, 100, 300, 300], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();+ s.execute("place.load", &json!({"base64": cmd::base64_encode(&png)})).unwrap();+ s.execute("place.drop", &json!({"frame": f})).unwrap();+ let xfs = |s: &Session| {+ let it = s.doc().unwrap().doc.item(designcraft_doc::ItemId(f)).unwrap().clone();+ (it.xf, it.graphic().unwrap().xf.translation())+ };+ let (frame0, g0) = xfs(&s);+ let v = ViewInfo { snap: SnapView::OFF, ..ViewInfo::at_zoom(1.0) };+ let at = s.layout().to_canvas(designcraft_doc::SpreadRef::Doc(0), designcraft_geom::Point::new(150.0, 150.0));+ s.set_tool("directSelection");+ s.pointer(&PointerEvent::new(PointerKind::Down, at.x, at.y), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, at.x + 20.0, at.y + 10.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, at.x + 30.0, at.y + 10.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, at.x + 30.0, at.y + 10.0), v).unwrap();+ assert!(s.doc().unwrap().selection.content);+ let (frame1, g1) = xfs(&s);+ assert_eq!(frame1, frame0, "the frame stays");+ assert_eq!(g1 - g0, designcraft_geom::Vec2::new(30.0, 10.0));+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(xfs(&s).1, g0, "one undo step");+ // Arrow keys nudge the selected content; Shift nudges ten times as far.+ s.set_tool("selection");+ s.tool_key(ToolKey::Right, Mods::default(), v).unwrap();+ s.tool_key(ToolKey::Down, Mods { shift: true, ..Default::default() }, v).unwrap();+ let (frame2, g2) = xfs(&s);+ assert_eq!(frame2, frame0);+ assert_eq!(g2 - g0, designcraft_geom::Vec2::new(1.0, 10.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);+ }diff --cc crates/tools/src/select.rsindex 7eed25a52,b2ac97731..27a02e60b--- a/crates/tools/src/select.rs+++ b/crates/tools/src/select.rs@@@ -3,14 -3,9 +3,15 @@@//! Click selects the frontmost item (Shift toggles), drag moves (Alt duplicates, Shift constrains),//! the 8 bounding-box handles resize (Shift keeps proportions, Alt from centre, Cmd scales content),//! empty-canvas drags make a marquee, double-clicking a text frame switches to the Type tool.+ //! A click on a selected text frame's in or out port loads the text cursor (see [`crate::thread`]).+//!+//! Content (a placed graphic, or items pasted into a frame) moves inside its frame: the Direct+//! Selection tool selects and drags it, the Selection tool drags it by the content grabber (the+//! circle at the frame's centre), and double-clicking a frame toggles between frame and content.+//! A selected placed graphic shows its own bounding box: its handles resize the graphic (Shift keeps+//! its proportions, Alt from its centre) and leave the frame as it is.-use designcraft_doc::{ItemId, SpreadRef};+use designcraft_doc::{Content, Item, ItemId, SpreadRef};use designcraft_geom::{Affine, Point, Rect, Vec2};use serde_json::{Value, json};@@@ -524,6 -473,19 +577,31 @@@ impl Tool for SelectionToolfn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {let p = ev.pos;+ if !self.direct+ && let Some(actions) = self.thread_pointer(cx, ev)+ {+ return actions;+ }++ // The second press of a double click on a frame with content: toggle between the frame++ // and its content.++ if !self.direct++ && matches!(ev.kind, PointerKind::Down | PointerKind::DoubleClick)++ && ev.click_count() == 2++ && let Some(id) = cx.hit(p).map(|(_, id)| cx.doc.top_level_of(id).unwrap_or(id))++ && cx.doc.item(id).is_some_and(holds_content)++ {++ self.drag = Drag::None;++ let content = !(cx.selection.content && cx.selection.contains(id));++ return vec![Action::Exec("selection.set".into(), json!({"ids": [id.0], "content": content}))];++ }+ // The second press of a double click on a text frame: edit its text.+ if matches!(ev.kind, PointerKind::Down | PointerKind::DoubleClick)+ && ev.click_count() == 2+ && let Some(actions) = edit_text_at(cx, p)+ {+ self.drag = Drag::None;+ return actions;+ }match ev.kind {PointerKind::Move => {self.hover_handle = handle_at(cx, p);@@@ -971,15 -867,13 +1034,20 @@@fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {match &self.drag {+ Drag::Place { start, cur } if crate::thread::is_drag(cx, *start, *cur) => {+ let Some((sr, r, guides)) = crate::thread::drag_frame(cx, *start, *cur) else { return vec![] };+ let r = Rect::from_points(cx.layout.to_canvas(sr, Point::new(r.x0, r.y0)), cx.layout.to_canvas(sr, Point::new(r.x1, r.y1)));+ std::iter::once(Overlay::Marquee(r)).chain(guides).collect()+ }Drag::Marquee { start, cur } => vec![Overlay::Marquee(Rect::from_points(*start, *cur))],+ Drag::Move { content: true, exclude, .. } => {+ let mut v: Vec<Overlay> = exclude.iter().map(|id| Overlay::ContentGhost(*id)).collect();+ v.extend(self.guides.iter().cloned());+ v+ }Drag::Move { .. } | Drag::Resize { .. } | Drag::Rotate { .. } | Drag::Anchor { .. } => self.guides.clone(),+ // The whole graphic shows while it's resized, outside the frame too.+ Drag::ContentResize { id, .. } => vec![Overlay::ContentGhost(*id)],Drag::None | Drag::Bracket { .. } => brackets(cx),_ => vec![],}@@@ -989,24 -883,12 +1057,27 @@@if matches!(self.drag, Drag::Bracket { .. }) || (matches!(self.drag, Drag::None) && bracket_at(cx, p).is_some()) {return Cursor::PathBracket;}+ if let Drag::Move { content: true, .. } = self.drag {+ return Cursor::HandGrab;+ }+ if let Drag::ContentResize { handle, .. } = self.drag {+ return handle_cursor(handle);+ }+ if matches!(self.drag, Drag::None)+ && !(self.direct && anchor_at(cx, p).is_some())+ && let Some((_, h)) = content_handle_at(cx, p)+ {+ return handle_cursor(h);+ }if self.direct {- return Cursor::ArrowHollow;+ let over_content = matches!(self.drag, Drag::None)+ && anchor_at(cx, p).is_none()+ && cx.hit(p).is_some_and(|(_, id)| cx.doc.item(id).is_some_and(holds_content));+ return if over_content { Cursor::Hand } else { Cursor::ArrowHollow };}+ if let Some(l) = self.loaded.and_then(|l| l.resolve(cx.doc)) {+ return if crate::thread::port_at(cx, p).is_some() { Cursor::LoadedText } else { l.cursor(cx, p) };+ }match self.drag {Drag::Move { .. } => return Cursor::Move,Drag::Resize { handle, .. } => return handle_cursor(handle),