Skip to content

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

Merge PR #1125: Direct Selection on a selected frame selects its image, so Delete keeps the frame

aiongg8227f29295d3
diff --cc ROADMAP.md
index 76c0ee095,9ba6ac5ef..b822656b0
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -455,11 -443,7 +455,12 @@@ Newest first
- **2026-10-16** · Lock Guides and Lock Column Guides are commands in View ▸ Grids & Guides (`view.lockGuides`, ⌥⌘;, and `view.lockColumnGuides`), so the control channel and MCP reach them. Lock Column Guides is an undo step, is saved with the document, on in new ones, and read from and written to IDML's `ColumnGuideLocked`, which export always wrote as locked (#1096). No readiness percentage change.
- **2026-10-16** · IDML: a page keeps column guides that were dragged off centre (InDesign's Custom columns). They were divided evenly on import, so the gutter sprang back to the middle; the imported positions now place the columns, with the canvas guides, snapping and text placement following them, and they are written back on export. Layout › Margins and Columns re-divides them evenly when the count or gutter changes, as InDesign's does. No readiness percentage change.
- **2026-10-16** · IDML: custom column positions are checked before they are used (#1096). A set must give two edges per column, ascending from the left margin to the right one; any other (a wrong count, unsorted or non-numeric values, a list longer than 216 columns allow, or positions left behind by a margin or page-size change) is the even split, in the canvas, on import and on export, instead of columns drawn outside the margins. No readiness percentage change.
+- **2026-10-21** · Swatches panel rows show InDesign's columns, drawn in code: a crossed pencil on the swatches that can't be edited ([None], [Registration], [Black]), the colour type (process or spot) and the colour mode (CMYK, RGB, Gray, or [None]'s and [Registration]'s own glyphs), in place of a lock and "CMYK" text. Tint reads 100 with nothing selected. No readiness percentage change.
+- **2026-10-21** · With a gradient fill or stroke, the Color panel shows the stop selected in the Gradient panel (the stop before a selected midpoint) with its values, and its C/M/Y/K or R/G/B sliders and spectrum colour that stop, keeping the others, as in InDesign. It showed "[None] — choose a colour on the ramp", and a spectrum click replaced the whole gradient with a flat colour. Found in the Learn Skills Daily course, chapter 24. No readiness percentage change.
+- **2026-10-20** · A new document's Swatches panel lists InDesign's defaults: [None], [Registration], [Paper], [Black] and six process colours (C=100, M=100, Y=100, C=15 M=100 Y=100, C=75 M=5 Y=100, C=100 M=90 Y=10); the extra M=100 Y=100, C=100 Y=100 and C=100 M=100 swatches are gone. No readiness percentage change.
+- **2026-10-21** · The readout beside the cursor while drawing or measuring ("W: 3.13 cm") is InDesign's light grey box with white text, measured from the tutorials' frames; High Contrast keeps it black. It was a dark translucent box. No readiness percentage change.
+- **2026-10-14** · The Direct Selection tool pressed on a corner or anchor of an object that isn't selected selects it and pulls just that point, as in InDesign (it moved the whole object). No readiness percentage change.
+ - **2026-10-16** · A Direct Selection click on an image whose frame is already selected selects the image, so Delete removes only the image and leaves the empty frame, as in InDesign. No readiness percentage change.
- **2026-10-21** · Properties › Character and Paragraph: ••• (More Options) expands the section in place, as InDesign's: Character adds vertical and horizontal scale, baseline shift, skew, language and OpenType, and All Caps, Small Caps, Superscript, Subscript, Underline and Strikethrough; Paragraph adds the left, right, first line and last line indents, space before and after, the drop cap's lines and characters, Align to Baseline Grid and Hyphenate. It used to open the Character or Paragraph panel; the language field moved under ••• as in InDesign. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.
- **2026-10-21** · The text Control panel has InDesign's two modes: A (Character Formatting Controls: font and style, size and leading, All Caps/Superscript/Underline and Small Caps/Subscript/Strikethrough, kerning and tracking, vertical and horizontal scale, baseline shift and skew, character style and language) and ¶ (Paragraph Formatting Controls: the nine alignments, left/first line and right/last line indents, space before and after, the drop cap's lines and characters, paragraph style, Hyphenate and Align to Baseline Grid). It used to show a fixed mix of both. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.
- **2026-10-20** · With the Type tool, the Control panel's font size, leading and tracking fields have a spinner and a list of common values, as in InDesign (auto leading in parentheses). No readiness percentage change.
diff --cc crates/engine/src/tests.rs
index e037ba0ff,456f6bb4d..0b1107509
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -1661,48 -1661,53 +1661,95 @@@ fn a_line_fits_when_its_baseline_does(
assert!(overset(&mut s, 50.0), "a baseline below the frame still oversets the line");
}
+#[test]
+fn direct_selection_pulls_one_corner_of_an_unselected_frame() {
+ // Chris Nielsen's "The Adobe InDesign Toolbox" (10:10): with the White Arrow, click outside,
+ // then press on a frame's corner and pull it: only that corner moves (a triangle, nearly).
+ use designcraft_tools::{PointerEvent, PointerKind, SnapView};
+ let mut s = Session::new();
+ s.execute("file.new", &json!({"width": 612, "height": 792, "facingPages": false})).unwrap();
+ let id = s.execute("frame.create", &json!({"rect": [156, 219, 455, 569], "content": "graphic"})).unwrap()["id"].as_u64().unwrap();
+ s.execute("edit.deselectAll", &json!({})).unwrap();
+ let corners = |s: &Session| {
+ let d = &s.doc().unwrap().doc;
+ let it = d.item(designcraft_doc::ItemId(id)).unwrap();
+ it.path.subpaths[0].anchors.iter().map(|a| it.xf * a.p).collect::<Vec<_>>()
+ };
+ let before = corners(&s);
+ s.set_tool("directSelection");
+ let v = ViewInfo { snap: SnapView::OFF, ..ViewInfo::at_zoom(1.0) };
+ let layout = s.layout();
+ let at = |x: f64, y: f64| layout.to_canvas(designcraft_doc::SpreadRef::Doc(0), designcraft_geom::Point::new(x, y));
+ let (a, b) = (at(455.0, 219.0), at(455.0, 150.0));
+ s.pointer(&PointerEvent::new(PointerKind::Down, a.x, a.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, a.x, a.y - 30.0), 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 after = corners(&s);
+ let moved: Vec<_> = before.iter().zip(&after).filter(|(p, q)| (**p - **q).hypot() > 1e-6).collect();
+ assert_eq!(moved.len(), 1, "one corner moved: {before:?} → {after:?}");
+ assert!((*moved[0].1 - designcraft_geom::Point::new(455.0, 150.0)).hypot() < 1e-6, "{after:?}");
+ assert_eq!(s.doc().unwrap().selection.items, [designcraft_doc::ItemId(id)], "the frame is selected");
+ // One undo step puts the corner back.
+ s.execute("edit.undo", &json!({})).unwrap();
+ assert_eq!(corners(&s), before);
+ // Away from its corners, the White Arrow still drags the whole unselected frame.
+ s.execute("edit.deselectAll", &json!({})).unwrap();
+ let (c, d) = (at(300.0, 219.0), at(300.0, 269.0));
+ s.pointer(&PointerEvent::new(PointerKind::Down, c.x, c.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, c.x, c.y + 20.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Drag, d.x, d.y), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, d.x, d.y), v).unwrap();
+ assert!(corners(&s).iter().zip(&before).all(|(p, q)| (p.y - q.y - 50.0).abs() < 1e-6), "{:?}", corners(&s));
+}
+
+ #[test]
+ fn direct_selection_on_a_selected_frame_deletes_only_its_image() {
+ use designcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey};
+ let dir = tempfile::tempdir().unwrap();
+ let png = dir.path().join("photo.png");
+ std::fs::write(&png, designcraft_render::Rendered { width: 100, height: 100, pixels: vec![40u8; 100 * 100 * 4] }.to_png()).unwrap();
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let frame = s.execute("frame.create", &json!({"rect": [100, 100, 200, 200]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("file.place", &json!({"path": png.to_string_lossy(), "frame": frame})).unwrap();
+ s.execute("selection.set", &json!({"ids": [frame], "content": false})).unwrap();
+ let v = ViewInfo::at_zoom(1.0);
+ let click = |s: &mut Session| {
+ s.pointer(&PointerEvent::new(PointerKind::Down, 110.0, 150.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, 110.0, 150.0), v).unwrap();
+ };
+ // The frame is selected with the Selection tool, then the image is clicked with Direct Selection.
+ s.set_tool("selection");
+ click(&mut s);
+ assert!(!s.doc().unwrap().selection.content);
+ s.set_tool("directSelection");
+ click(&mut s);
+ assert!(s.doc().unwrap().selection.content, "Direct Selection selects the image inside the selected frame");
+ assert!(s.tool_key(ToolKey::Delete, Mods::default(), v).unwrap());
+ let st = s.doc().unwrap();
+ let it = st.doc.item(designcraft_doc::ItemId(frame)).expect("the frame stays");
+ assert!(matches!(it.content, designcraft_doc::Content::Unassigned), "{:?}", it.content);
+ assert_eq!(st.selection.items, vec![designcraft_doc::ItemId(frame)]);
+ // A frame holding pasted-in items: the click selects them too, so arrow keys move them.
+ let inner = s.execute("frame.create", &json!({"rect": [320, 120, 360, 160]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("selection.set", &json!({"ids": [inner]})).unwrap();
+ s.execute("edit.cut", &json!({})).unwrap();
+ let holder = s.execute("frame.create", &json!({"rect": [300, 100, 400, 200]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("selection.set", &json!({"ids": [holder]})).unwrap();
+ s.execute("edit.pasteInto", &json!({})).unwrap();
+ s.set_tool("selection");
+ s.pointer(&PointerEvent::new(PointerKind::Down, 340.0, 140.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, 340.0, 140.0), v).unwrap();
+ assert_eq!(s.doc().unwrap().selection.items, vec![designcraft_doc::ItemId(holder)]);
+ assert!(!s.doc().unwrap().selection.content);
+ s.set_tool("directSelection");
+ s.pointer(&PointerEvent::new(PointerKind::Down, 340.0, 140.0), v).unwrap();
+ s.pointer(&PointerEvent::new(PointerKind::Up, 340.0, 140.0), v).unwrap();
+ let st = s.doc().unwrap();
+ assert!(st.selection.content && st.selection.items == [designcraft_doc::ItemId(holder)], "the pasted-in items are selected: {:?}", st.selection);
+ }
+
/// Issue #1637: with several objects selected, a click on one of them (no drag) makes it the key
/// object, and Align to Key Object leaves it in place. A second click on it drops the key.
#[test]