DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge content-move: move a placed graphic inside its frame
aionggbafd86d65ee8
diff --cc crates/engine/src/cmd/object.rsindex 7627d5569,0456dd05c..b4d65ec60--- a/crates/engine/src/cmd/object.rs+++ b/crates/engine/src/cmd/object.rs@@@ -2925,104 -2774,74 +2984,176 @@@ mod blend_mode_tests}}+#[cfg(test)]+mod reorder_tests {+ use super::*;++ fn frame(s: &mut Session) -> u64 {+ s.execute("frame.create", &json!({"rect": [0, 0, 10, 10]})).unwrap()["id"].as_u64().unwrap()+ }++ /// Top-level objects of the first spread on `layer`, topmost first.+ fn stack(s: &Session, layer: u64) -> Vec<u64> {+ let d = &s.doc().unwrap().doc;+ d.spreads[0].items.iter().rev().filter(|i| i.layer.0 == layer).map(|i| i.id.0).collect()+ }++ #[test]+ fn reorder_within_and_across_layers_validates_and_undoes() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let l1 = s.doc().unwrap().doc.layers[0].id.0;+ let l2 = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();+ s.execute("layer.activate", &json!({"id": l1})).unwrap();+ let (a, b, c) = (frame(&mut s), frame(&mut s), frame(&mut s));+ s.execute("layer.activate", &json!({"id": l2})).unwrap();+ let (x, y) = (frame(&mut s), frame(&mut s));+ assert_eq!(stack(&s, l1), [c, b, a]);+ s.execute("object.reorder", &json!({"ids": [a], "above": c})).unwrap();+ assert_eq!(stack(&s, l1), [a, c, b]);+ s.execute("object.reorder", &json!({"ids": [b], "index": 0})).unwrap();+ assert_eq!(stack(&s, l1), [b, a, c]);+ // To another layer at a position.+ s.execute("object.reorder", &json!({"ids": [a], "layer": l2, "index": 1})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c], vec![y, a, x]));+ s.execute("object.reorder", &json!({"ids": [x, y], "below": c})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c, y, x], vec![a]));+ // Bad input is an error and changes nothing.+ let before = s.doc().unwrap().doc.clone();+ for bad in [+ json!({"ids": [999], "index": 0}),+ json!({"ids": [b], "index": 4}),+ json!({"ids": [b], "above": b}),+ json!({"ids": [b], "above": 999}),+ json!({"ids": [b], "layer": 999}),+ json!({"ids": [b], "layer": l2, "above": c}),+ json!({"ids": [b], "above": c, "index": 0}),+ json!({"ids": [b], "index": "top"}),+ json!({"ids": []}),+ ] {+ assert!(s.execute("object.reorder", &bad).is_err(), "{bad}");+ assert_eq!(*s.doc().unwrap().doc, *before, "{bad}");+ }+ // The bottom of a layer is index = its count.+ s.execute("object.reorder", &json!({"ids": [b], "index": 3})).unwrap();+ assert_eq!(stack(&s, l1), [c, y, x, b]);+ // A reorder that changes nothing adds no undo step.+ let undo = |s: &Session| s.doc().unwrap().history.undo.len();+ let steps = undo(&s);+ s.execute("object.reorder", &json!({"ids": [x], "index": 2})).unwrap();+ s.execute("object.reorder", &json!({"ids": [y], "above": x})).unwrap();+ s.execute("object.reorder", &json!({"ids": [c], "layer": l1, "index": 0})).unwrap();+ assert_eq!(stack(&s, l1), [c, y, x, b]);+ assert_eq!(undo(&s), steps);+ // One undo step per reorder.+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(stack(&s, l1), [b, c, y, x]);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!((stack(&s, l1), stack(&s, l2)), (vec![b, c], vec![y, a, x]));+ }++ #[test]+ fn group_members_reorder_only_within_their_group() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let (a, b, c) = (frame(&mut s), frame(&mut s), frame(&mut s));+ let g = s.execute("object.group", &json!({"ids": [a, b]})).unwrap()["id"].as_u64().unwrap();+ let kids = |s: &Session| s.doc().unwrap().doc.item(ItemId(g)).unwrap().children().iter().map(|i| i.id.0).collect::<Vec<_>>();+ assert_eq!(kids(&s), [a, b]);+ s.execute("object.reorder", &json!({"ids": [a], "above": b})).unwrap();+ assert_eq!(kids(&s), [b, a]);+ s.execute("object.reorder", &json!({"ids": [a], "index": 1})).unwrap();+ assert_eq!(kids(&s), [a, b]);+ let before = s.doc().unwrap().doc.clone();+ assert!(s.execute("object.reorder", &json!({"ids": [a], "above": c})).is_err(), "out of the group");+ assert!(s.execute("object.reorder", &json!({"ids": [c], "above": a})).is_err(), "into the group");+ assert!(s.execute("object.reorder", &json!({"ids": [a, c], "index": 0})).is_err(), "mixed parents");+ assert_eq!(*s.doc().unwrap().doc, *before);+ }++ #[test]+ fn moving_a_group_member_to_a_layer_moves_its_group() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let (a, b) = (frame(&mut s), frame(&mut s));+ let g = s.execute("object.group", &json!({"ids": [a, b]})).unwrap()["id"].as_u64().unwrap();+ let art = s.execute("layer.new", &json!({"name": "Art"})).unwrap()["id"].as_u64().unwrap();+ let r = s.execute("object.setLayer", &json!({"ids": [a, b], "layer": art})).unwrap();+ assert_eq!(r["changed"], 1, "the group, once");+ let d = &s.doc().unwrap().doc;+ assert!([g, a, b].iter().all(|i| d.item(ItemId(*i)).unwrap().layer.0 == art));+ assert!(s.execute("object.setLayer", &json!({"ids": [a], "layer": 999})).is_err());+ }+}+++ #[cfg(test)]+ mod content_move_tests {+ use super::*;++ /// A session with a 40×20 image placed in a frame at (100, 100)–(300, 300).+ fn placed() -> (Session, ItemId) {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ 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": super::super::base64_encode(&png)})).unwrap();+ s.execute("place.drop", &json!({"frame": f})).unwrap();+ (s, ItemId(f))+ }++ /// Spread bounds of the frame and of its graphic.+ fn boxes(s: &Session, id: ItemId) -> (Rect, Rect) {+ let it = s.doc().unwrap().doc.item(id).unwrap().clone();+ let g = it.graphic().unwrap();+ (it.bounds(), (it.xf * g.xf).transform_rect_bbox(Rect::new(0.0, 0.0, g.size.0, g.size.1)))+ }++ fn near(a: Rect, b: Rect) -> bool {+ [a.x0 - b.x0, a.y0 - b.y0, a.x1 - b.x1, a.y1 - b.y1].iter().all(|d| d.abs() < 1e-6)+ }++ #[test]+ fn content_moves_inside_the_frame_in_one_undo_step() {+ let (mut s, f) = placed();+ let (frame0, g0) = boxes(&s, f);+ s.execute("selection.set", &json!({"ids": [f.0], "content": true})).unwrap();+ s.execute("transform.move", &json!({"dx": 10, "dy": -5})).unwrap();+ let (frame1, g1) = boxes(&s, f);+ assert!(near(frame1, frame0), "the frame stays");+ assert!(near(g1, g0 + Vec2::new(10.0, -5.0)), "{g1:?}");+ s.execute("edit.undo", &json!({})).unwrap();+ assert!(near(boxes(&s, f).1, g0));+ // Explicit ids with `content` act on the content whatever the selection is.+ s.execute("selection.set", &json!({"ids": [f.0]})).unwrap();+ s.execute("transform.move", &json!({"ids": [f.0], "content": true, "dx": 3})).unwrap();+ assert!(near(boxes(&s, f).0, frame0) && near(boxes(&s, f).1, g0 + Vec2::new(3.0, 0.0)));+ // A frame selection moves frame and content together.+ s.execute("transform.move", &json!({"dx": 4})).unwrap();+ assert!(near(boxes(&s, f).0, frame0 + Vec2::new(4.0, 0.0)) && near(boxes(&s, f).1, g0 + Vec2::new(7.0, 0.0)));+ }++ #[test]+ fn content_moves_on_the_page_axes_in_a_rotated_frame_and_pasted_items_move_too() {+ let (mut s, f) = placed();+ s.execute("transform.rotate", &json!({"ids": [f.0], "angle": 90})).unwrap();+ let (frame0, g0) = boxes(&s, f);+ s.execute("transform.move", &json!({"ids": [f.0], "content": true, "dx": 10})).unwrap();+ let (frame1, g1) = boxes(&s, f);+ assert!(near(frame1, frame0) && near(g1, g0 + Vec2::new(10.0, 0.0)), "{g0:?} → {g1:?}");+ // Items pasted into a frame are its content.+ let a = s.execute("frame.create", &json!({"rect": [400, 100, 420, 120], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [a]})).unwrap();+ s.execute("edit.copy", &json!({})).unwrap();+ let b = s.execute("frame.create", &json!({"rect": [400, 300, 500, 400], "content": "unassigned"})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": [b]})).unwrap();+ s.execute("edit.pasteInto", &json!({})).unwrap();+ let kids = |s: &Session| {+ let it = s.doc().unwrap().doc.item(ItemId(b)).unwrap().clone();+ (it.bounds(), it.children().iter().map(|c| it.xf.transform_rect_bbox(c.bounds())).collect::<Vec<_>>())+ };+ let (fb0, k0) = kids(&s);+ s.execute("transform.move", &json!({"ids": [b], "content": true, "dx": 5, "dy": 6})).unwrap();+ let (fb1, k1) = kids(&s);+ assert!(near(fb1, fb0) && near(k1[0], k0[0] + Vec2::new(5.0, 6.0)), "{k0:?} → {k1:?}");+ }+ }diff --cc crates/engine/src/tests.rsindex 7da76a658,7e043a10a..5ef6003c4--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -593,255 -562,37 +593,290 @@@ fn commands_take_non_object_params_with}}+/// 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);+}++#[test]+fn preflight_distinguishes_unplaced_stories_and_locates_footnote_overset() {+ use designcraft_doc::{AnchorPosition, AnchoredObject, ParaFormat, SpreadRef, Story, StoryId};+ use designcraft_geom::Rect;+ let mut s = session();+ let doc = Arc::make_mut(&mut s.doc_mut().unwrap().doc);+ let layer = doc.default_layer();+ let (host, body) = doc.add_text_frame(SpreadRef::Doc(0), Rect::new(20.0, 20.0, 400.0, 600.0), layer, "Body", ParaFormat::default()).unwrap();+ let (frame, _) = doc.add_text_frame(SpreadRef::Doc(0), Rect::new(0.0, 0.0, 5.0, 2.0), layer, "Overflow", ParaFormat::default()).unwrap();+ let item = doc.item(frame).unwrap().clone();+ doc.spread_mut(SpreadRef::Doc(0)).unwrap().items.retain(|i| i.id != frame);+ let story = doc.story_mut(body).unwrap();+ story.insert_note(4, "Note", ParaFormat::default());+ Arc::make_mut(&mut story.notes[0]).text.insert_object(0, AnchoredObject::new(item, AnchorPosition::Inline { y_offset: 0.0 }));+ let unplaced = StoryId(doc.alloc());+ doc.stories.insert(unplaced, Arc::new(Story::with_text(unplaced, "Unplaced", ParaFormat::default())));+ doc.check().unwrap();+ let issues = s.execute("preflight.run", &json!({})).unwrap();+ let issues = issues["issues"].as_array().unwrap();+ let overset: Vec<_> = issues.iter().filter(|i| i["kind"] == "overset").collect();+ assert_eq!(overset.len(), 1, "{issues:?}");+ assert_eq!(overset[0]["item"], host.0);+ assert_eq!(overset[0]["page"], 0);+ let unplaced = issues.iter().find(|i| i["kind"] == "unplacedStory").unwrap();+ assert_eq!(unplaced["severity"], "warning");+ assert!(unplaced.get("page").is_none());+}++#[test]+fn preflight_mojikumi_uses_the_same_supported_rules_as_composition() {+ let mut s = session();+ s.execute("frame.create", &json!({"rect": [36, 36, 300, 300], "content": "text", "text": "中文 A1"})).unwrap();+ let story = s.doc().unwrap().doc.stories.keys().next().unwrap().0;+ s.execute("text.select", &json!({"story": story, "anchor": 0, "focus": 1})).unwrap();+ for (name, unsupported) in [("SimpChineseDefault", false), ("LineEndAllOneHalfEmEnum", false), ("UnknownPreset", true), ("Nothing", false)] {+ s.execute("type.para", &json!({"attrs": {"mojikumi": name, "kinsokuType": "KinsokuPushInFirst"}})).unwrap();+ let result = s.execute("preflight.run", &json!({})).unwrap();+ let warnings: Vec<_> = result["issues"].as_array().unwrap().iter().filter(|i| i["kind"] == "unsupportedTypography").collect();+ assert_eq!(!warnings.is_empty(), unsupported, "{name}: {warnings:?}");+ }+}++#[test]+fn paragraph_style_edit_persists_attrs_and_rename() {+ let mut s = session();+ let name =+ s.execute("style.paragraph.create", &json!({"name": "Body Copy", "para": {"align": "left"}})).unwrap()["name"].as_str().unwrap().to_string();+ s.execute("style.paragraph.edit", &json!({"name": name, "para": {"align": "center"}})).unwrap();+ {+ let st = s.doc().unwrap();+ let style = st.doc.styles.para(&name).expect("style still exists");+ assert_eq!(style.para.align, Some(designcraft_doc::Align::Center), "edited attribute persisted");+ }+ // Renaming updates the style definition itself, and every place it's referenced.+ s.execute("style.paragraph.edit", &json!({"name": name, "rename": "Body Text"})).unwrap();+ let st = s.doc().unwrap();+ assert!(st.doc.styles.para("Body Text").is_some(), "renamed style exists under the new name");+ assert!(st.doc.styles.para(&name).is_none(), "old name is gone");+}++#[test]+fn paragraph_style_edit_rejects_based_on_cycle() {+ let mut s = session();+ let a = s.execute("style.paragraph.create", &json!({"name": "A"})).unwrap()["name"].as_str().unwrap().to_string();+ let b = s.execute("style.paragraph.create", &json!({"name": "B", "basedOn": a})).unwrap()["name"].as_str().unwrap().to_string();+ let r = s.execute("style.paragraph.edit", &json!({"name": a, "basedOn": b}));+ assert!(r.is_err(), "A based on B based on A must be rejected");+}++#[test]+fn paragraph_style_delete_reassigns_affected_text() {+ let mut s = session();+ let name = s.execute("style.paragraph.create", &json!({"name": "Caption"})).unwrap()["name"].as_str().unwrap().to_string();+ let sid = s.execute("frame.create", &json!({"rect": [36, 36, 300, 200], "content": "text"})).unwrap()["story"].as_u64().unwrap();+ s.execute("text.insert", &json!({"text": "Hello, world"})).unwrap();+ s.execute("text.select", &json!({"story": sid, "anchor": 0, "focus": 0})).unwrap();+ s.execute("style.paragraph.apply", &json!({"name": name})).unwrap();+ {+ let st = s.doc().unwrap();+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");+ assert_eq!(story.paras[0].style, name, "style applied before delete");+ }+ s.execute("style.paragraph.delete", &json!({"name": name, "replaceWith": designcraft_doc::BASIC_PARAGRAPH})).unwrap();+ let st = s.doc().unwrap();+ assert!(st.doc.styles.para(&name).is_none(), "deleted style is gone");+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");+ assert_eq!(story.paras[0].style, designcraft_doc::BASIC_PARAGRAPH, "affected paragraph reassigned to the replacement style");+}++#[test]+fn paragraph_style_delete_rejects_builtin_styles() {+ let mut s = session();+ let r = s.execute("style.paragraph.delete", &json!({"name": designcraft_doc::BASIC_PARAGRAPH}));+ assert!(r.is_err(), "built-in styles can't be deleted");+}++#[test]+fn character_style_edit_persists_attrs_and_rename() {+ let mut s = session();+ let name = s.execute("style.character.create", &json!({"name": "Key Term", "chars": {"fontStyle": "Bold"}})).unwrap()["name"]+ .as_str()+ .unwrap()+ .to_string();+ s.execute("style.character.edit", &json!({"name": name, "chars": {"tracking": 20.0}})).unwrap();+ {+ let st = s.doc().unwrap();+ let style = st.doc.styles.char_style(&name).expect("style still exists");+ assert_eq!(style.chars.tracking, Some(20.0), "edited attribute persisted");+ }+ // Renaming updates the style definition itself, and every place it's referenced.+ s.execute("style.character.edit", &json!({"name": name, "rename": "Emphasis"})).unwrap();+ let st = s.doc().unwrap();+ assert!(st.doc.styles.char_style("Emphasis").is_some(), "renamed style exists under the new name");+ assert!(st.doc.styles.char_style(&name).is_none(), "old name is gone");+}++#[test]+fn character_style_edit_rejects_based_on_cycle() {+ let mut s = session();+ let a = s.execute("style.character.create", &json!({"name": "A"})).unwrap()["name"].as_str().unwrap().to_string();+ let b = s.execute("style.character.create", &json!({"name": "B", "basedOn": a})).unwrap()["name"].as_str().unwrap().to_string();+ let r = s.execute("style.character.edit", &json!({"name": a, "basedOn": b}));+ assert!(r.is_err(), "A based on B based on A must be rejected");+}++#[test]+fn character_style_delete_reassigns_affected_text() {+ let mut s = session();+ let name = s.execute("style.character.create", &json!({"name": "Key Term"})).unwrap()["name"].as_str().unwrap().to_string();+ let r = s.execute("frame.create", &json!({"rect": [36, 36, 300, 200], "content": "text"})).unwrap();+ let sid = r["story"].as_u64().unwrap();+ s.execute("text.insert", &json!({"text": "Hello, world"})).unwrap();+ s.execute("text.select", &json!({"story": sid, "anchor": 0, "focus": 5})).unwrap();+ s.execute("style.character.apply", &json!({"name": name})).unwrap();+ {+ let st = s.doc().unwrap();+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");+ assert_eq!(story.chars[0].format.style, name, "style applied before delete");+ }+ s.execute("style.character.delete", &json!({"name": name, "replaceWith": designcraft_doc::NO_CHAR_STYLE})).unwrap();+ let st = s.doc().unwrap();+ assert!(st.doc.styles.char_style(&name).is_none(), "deleted style is gone");+ let story = st.doc.stories.get(&designcraft_doc::StoryId(sid)).expect("story exists");+ assert_eq!(story.chars[0].format.style, designcraft_doc::NO_CHAR_STYLE, "affected run reassigned to the replacement style");+}++#[test]+fn character_style_delete_rejects_builtin_styles() {+ let mut s = session();+ let r = s.execute("style.character.delete", &json!({"name": designcraft_doc::NO_CHAR_STYLE}));+ assert!(r.is_err(), "built-in styles can't be deleted");+}+++ #[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));+ }diff --cc crates/tools/src/select.rsindex 84e12d3b3,46e0533df..5f2cf0197--- a/crates/tools/src/select.rs+++ b/crates/tools/src/select.rs@@@ -3,9 -3,12 +3,13 @@@//! 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.- use designcraft_doc::{ItemId, SpreadRef};+ use designcraft_doc::{Content, Item, ItemId, SpreadRef};use designcraft_geom::{Affine, Point, Rect, Vec2};use serde_json::{Value, json};@@@ -425,19 -445,6 +499,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 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;+ }++ // 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}))];++ }match ev.kind {PointerKind::Move => {self.hover_handle = handle_at(cx, p);@@@ -802,19 -855,27 +919,30 @@@fn overlays(&self, _cx: &ToolContext) -> Vec<Overlay> {match &self.drag {- Drag::Marquee { start, cur } => vec![Overlay::Marquee(Rect::from_points(*start, *cur))],+ Drag::Marquee { start, cur } | Drag::Place { 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(),_ => vec![],}}fn cursor(&self, cx: &ToolContext, p: Point, _m: Mods) -> Cursor {+ if let Drag::Move { content: true, .. } = self.drag {+ return Cursor::HandGrab;+ }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),diff --cc crates/tools/src/tests.rsindex f898755bf,659f2c523..8801acc2d--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@@ -706,236 -706,105 +706,350 @@@ fn pen_click_snaps_to_a_guide()assert!((x - 100.0).abs() < 1e-6, "anchor x {x}");}+/// A text frame with overset text (selected), an empty frame and a threaded pair x → y, on page 1.+struct ThreadDoc {+ d: Document,+ l: CanvasLayout,+ s: Selection,+ c: Cache,+ /// The selected text frame.+ a: ItemId,+ /// An empty (unassigned) frame.+ e: ItemId,+ x: ItemId,+ y: ItemId,+}++fn thread_doc() -> ThreadDoc {+ let mut d = Document::new(&NewDocument { pages: 2, ..Default::default() });+ let lid = d.default_layer();+ let (a, _) = d+ .add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 250.0, 160.0), lid, &"Words flow on. ".repeat(40), ParaFormat::default())+ .unwrap();+ let e = ItemId(d.alloc());+ d.insert_item(SpreadRef::Doc(0), Item::new(e, lid, Shape::Rectangle, shapes::rectangle(Rect::new(100.0, 400.0, 250.0, 500.0))), None).unwrap();+ let (x, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(300.0, 100.0, 450.0, 160.0), lid, "x", ParaFormat::default()).unwrap();+ let (y, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(300.0, 400.0, 450.0, 500.0), lid, "", ParaFormat::default()).unwrap();+ d.thread(x, y).unwrap();+ let l = CanvasLayout::new(&d, false);+ ThreadDoc { s: Selection::items(vec![a]), c: Cache::new(), l, d, a, e, x, y }+}++impl ThreadDoc {+ fn cx(&self) -> ToolContext<'_> {+ ctx(&self.d, &self.s, &self.c, &self.l)+ }+ /// Canvas point of a spread-0 point.+ fn at(&self, x: f64, y: f64) -> Point {+ self.l.to_canvas(SpreadRef::Doc(0), Point::new(x, y))+ }+ fn port(&self, id: ItemId, out: bool) -> Point {+ thread::port_center(&self.d, &self.l, id, out, 1.0).unwrap()+ }+}++fn click(t: &mut Box<dyn Tool>, cx: &ToolContext, p: Point, mods: Mods) -> Vec<Action> {+ let mut v = t.pointer(cx, &PointerEvent::new(PointerKind::Down, p.x, p.y).with_mods(mods));+ v.extend(t.pointer(cx, &PointerEvent::new(PointerKind::Up, p.x, p.y).with_mods(mods)));+ v+}++fn thread_exec(p: serde_json::Value) -> Vec<Action> {+ vec![Action::Exec("text.thread".into(), p)]+}++#[test]+fn out_port_loads_text_and_a_click_threads_an_empty_frame() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ let port = td.port(td.a, true);+ // The out port sits on the right edge, 12 px above the bottom-right corner.+ assert!((port - td.at(250.0, 148.0)).hypot() < 1e-9, "{port:?}");+ // A press just off the port's centre still loads (any zoom: tolerance is in pixels).+ assert!(click(&mut t, &cx, port + designcraft_geom::Vec2::new(3.0, -3.0), Mods::default()).is_empty());+ assert_eq!(t.cursor(&cx, td.at(500.0, 700.0), Mods::default()), Cursor::LoadedText);+ let over_e = td.at(175.0, 450.0);+ assert_eq!(t.cursor(&cx, over_e, Mods::default()), Cursor::ThreadLink);+ // A frame something already threads into can't join; neither can the loaded frame itself.+ assert_eq!(t.cursor(&cx, td.at(375.0, 450.0), Mods::default()), Cursor::NotAllowed);+ assert_eq!(t.cursor(&cx, td.at(175.0, 130.0), Mods::default()), Cursor::LoadedText);+ assert_eq!(click(&mut t, &cx, over_e, Mods::default()), thread_exec(serde_json::json!({"from": td.a.0, "to": td.e.0})));+ // Unloaded again: the cursor and clicks are back to normal.+ assert_eq!(t.cursor(&cx, over_e, Mods::default()), Cursor::Arrow);+}++#[test]+fn ports_hit_at_any_zoom() {+ let td = thread_doc();+ let mut cx = td.cx();+ cx.zoom = 4.0;+ let port = thread::port_center(&td.d, &td.l, td.a, false, 4.0).unwrap();+ assert!((port - td.at(100.0, 100.0 + 14.5 / 4.0)).hypot() < 1e-9);+ assert_eq!(thread::port_at(&cx, port + designcraft_geom::Vec2::new(1.5, 1.5)), Some((td.a, false)));+ assert_eq!(thread::port_at(&cx, port + designcraft_geom::Vec2::new(4.0, 0.0)), None, "8 screen px away at 4×");+}++#[test]+fn loaded_click_on_empty_page_makes_a_column_frame() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.a, true), Mods::default());+ let col = td.d.spreads[0].pages[0].column_rects()[0];+ let a = click(&mut t, &cx, td.at(200.0, 600.0), Mods::default());+ assert_eq!(a, thread_exec(serde_json::json!({"from": td.a.0, "rect": [col.x0, 600.0, col.x1, col.y1], "spread": {"kind": "doc", "index": 0}})));+}++#[test]+fn loaded_drag_makes_a_frame_of_that_size_and_shift_autoflows() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.a, true), Mods::default());+ let (p0, p1) = (td.at(320.0, 560.0), td.at(470.0, 700.0));+ let shift = Mods { shift: true, ..Default::default() };+ assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p0.x, p0.y).with_mods(shift)).is_empty());+ assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, p1.x, p1.y).with_mods(shift)).is_empty());+ assert_eq!(t.overlays(&cx), vec![Overlay::Marquee(Rect::from_points(p0, p1))]);+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, p1.x, p1.y).with_mods(shift));+ assert_eq!(+ a,+ thread_exec(+ serde_json::json!({"from": td.a.0, "rect": [320.0, 560.0, 470.0, 700.0], "spread": {"kind": "doc", "index": 0}, "autoflow": true})+ )+ );+ assert_eq!(t.cursor(&cx, td.at(500.0, 700.0), Mods::default()), Cursor::Arrow, "autoflow unloads");+}++#[test]+fn alt_click_stays_loaded() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.a, true), Mods::default());+ let alt = Mods { alt: true, ..Default::default() };+ assert_eq!(click(&mut t, &cx, td.at(175.0, 450.0), alt), thread_exec(serde_json::json!({"from": td.a.0, "to": td.e.0})));+ assert_eq!(t.cursor(&cx, td.at(500.0, 700.0), Mods::default()), Cursor::LoadedText);+}++#[test]+fn escape_unloads_and_keeps_the_selection() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.a, true), Mods::default());+ assert_eq!(t.key(&cx, ToolKey::Escape, Mods::default()), vec![Action::Cancel]);+ assert_eq!(t.cursor(&cx, td.at(500.0, 700.0), Mods::default()), Cursor::Arrow);+ // An ordinary click on empty space deselects again.+ let p = td.at(500.0, 700.0);+ assert_eq!(+ t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y)),+ vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": []}))]+ );+}++#[test]+fn loaded_click_on_the_linked_frame_unthreads() {+ // x is selected; its out port links to y.+ let td = thread_doc();+ let td = ThreadDoc { s: Selection::items(vec![td.x]), ..td };+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.x, true), Mods::default());+ let over_y = td.at(375.0, 450.0);+ assert_eq!(t.cursor(&cx, over_y, Mods::default()), Cursor::Unthread);+ assert_eq!(+ click(&mut t, &cx, over_y, Mods::default()),+ vec![Action::Exec("text.unthread".into(), serde_json::json!({"frame": td.x.0, "side": "after"}))]+ );+ // From y's in port, x is the frame before.+ let td = ThreadDoc { s: Selection::items(vec![td.y]), ..td };+ let cx = td.cx();+ click(&mut t, &cx, td.port(td.y, false), Mods::default());+ assert_eq!(+ click(&mut t, &cx, td.at(375.0, 130.0), Mods::default()),+ vec![Action::Exec("text.unthread".into(), serde_json::json!({"frame": td.y.0, "side": "before"}))]+ );+}++#[test]+fn in_port_threads_in_front() {+ let td = thread_doc();+ let cx = td.cx();+ let mut t = create("selection");+ click(&mut t, &cx, td.port(td.a, false), Mods::default());+ assert_eq!(click(&mut t, &cx, td.at(175.0, 450.0), Mods::default()), thread_exec(serde_json::json!({"from": td.e.0, "to": td.a.0})));+}++#[test]+fn double_click_on_a_port_breaks_its_link() {+ let td = thread_doc();+ let td = ThreadDoc { s: Selection::items(vec![td.x]), ..td };+ let cx = td.cx();+ // A double click sent as such (control channel), and the canvas's second press.+ let second = |p: Point| [PointerEvent::new(PointerKind::DoubleClick, p.x, p.y), PointerEvent::new(PointerKind::Down, p.x, p.y).with_clicks(2)];+ let p = td.port(td.x, true);+ for ev in second(p) {+ let mut t = create("selection");+ click(&mut t, &cx, p, Mods::default());+ let a = t.pointer(&cx, &ev);+ assert_eq!(a, vec![Action::Exec("text.unthread".into(), serde_json::json!({"frame": td.x.0, "side": "after"}))], "{ev:?}");+ assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, p.x, p.y)).is_empty());+ assert_eq!(t.cursor(&cx, td.at(500.0, 700.0), Mods::default()), Cursor::Arrow);+ // The in port of the first frame has no link: nothing to break.+ let q = td.port(td.x, false);+ for ev in second(q) {+ assert!(t.pointer(&cx, &ev).is_empty(), "{ev:?}");+ }+ }+}++#[test]+fn clicks_in_a_row_edit_and_select_text() {+ let mut d = Document::new(&NewDocument::default());+ let lid = d.default_layer();+ let (fid, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 300.0, 200.0), lid, "Two words", ParaFormat::default()).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 (x, y) = (150.0 + off.x, 110.0 + off.y);+ let press = |n: u8| PointerEvent::new(PointerKind::Down, x, y).with_clicks(n);+ // Selection tool: the second press of a double click edits the text there.+ let mut t = create("selection");+ let a = t.pointer(&cx, &press(1));+ assert!(matches!(&a[0], Action::Exec(id, _) if id == "selection.set"), "{a:?}");+ t.pointer(&cx, &PointerEvent::new(PointerKind::Up, x, y));+ let a = t.pointer(&cx, &press(2));+ assert_eq!(a.first(), Some(&Action::SwitchTool("type".into())));+ assert!(matches!(&a[1], Action::Exec(id, p) if id == "text.placeCaret" && p["frame"] == fid.0), "{a:?}");+ // Type tool: word, line, paragraph, then the story.+ let mut t = create("type");+ let unit = |a: Vec<Action>| match a.as_slice() {+ [Action::Exec(id, p)] if id == "text.selectAt" => p["unit"].as_str().map(str::to_string),+ [Action::Exec(id, _)] if id == "text.placeCaret" => None,+ other => panic!("{other:?}"),+ };+ assert_eq!(unit(t.pointer(&cx, &press(1))), None);+ for (n, want) in [(2, "word"), (3, "line"), (4, "paragraph"), (5, "story"), (9, "story")] {+ assert_eq!(unit(t.pointer(&cx, &press(n))).as_deref(), Some(want), "{n} clicks");+ }+ // A double click sent as such (control channel) selects a word too.+ assert_eq!(unit(t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, x, y))).as_deref(), Some("word"));+ // Moving a little while pressed keeps the unit selected.+ assert!(t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, x + 2.0, y)).is_empty());+}+++ /// A 100×100 frame at (100, 100) holding a 200×100 graphic that overhangs it.+ fn graphic_frame(doc: &mut Document) -> ItemId {+ let id = ItemId(doc.alloc());+ let mut item = Item::new(id, doc.default_layer(), Shape::Rectangle, shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0)));+ item.content = designcraft_doc::Content::Graphic(designcraft_doc::Graphic {+ asset: designcraft_doc::AssetId(1),+ size: (200.0, 100.0),+ xf: designcraft_geom::Affine::translate((50.0, 100.0)),+ auto_fit: Default::default(),+ fit_align: 4,+ crop: [0.0; 4],++ wrap: Default::default(),+ });+ doc.insert_item(SpreadRef::Doc(0), item, None).unwrap();+ id+ }++ fn preview_params(a: &[Action]) -> serde_json::Value {+ match a.last() {+ Some(Action::Preview(cmd, p)) if cmd == "transform.move" => p.clone(),+ other => panic!("{other:?}"),+ }+ }++ #[test]+ fn direct_selection_drags_content_inside_its_frame() {+ let mut d = Document::new(&NewDocument::default());+ let f = graphic_frame(&mut d);+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let none = Selection::default();+ let mut t = create("directSelection");+ let at = spread_pt(&l, 120.0, 130.0);+ let a = t.pointer(&ctx(&d, &none, &c, &l), &PointerEvent::new(PointerKind::Down, at.x, at.y));+ assert_eq!(a, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0], "content": true}))]);+ let sel = Selection { content: true, ..Selection::items(vec![f]) };+ let cx = ctx(&d, &sel, &c, &l);+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, at.x + 15.0, at.y - 4.0));+ assert_eq!(a.first(), Some(&Action::Begin("Move Content".into())));+ let p = preview_params(&a);+ assert_eq!(+ (p["dx"].as_f64(), p["dy"].as_f64(), &p["content"], &p["ids"]),+ (Some(15.0), Some(-4.0), &serde_json::json!(true), &serde_json::json!([f.0]))+ );+ assert_eq!(t.cursor(&cx, at, Mods::default()), Cursor::HandGrab);+ assert!(t.overlays(&cx).contains(&Overlay::ContentGhost(f)));+ // Shift keeps the drag on one axis.+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, at.x + 15.0, at.y - 4.0).with_mods(Mods { shift: true, ..Default::default() }));+ let p = preview_params(&a);+ assert_eq!((p["dx"].as_f64(), p["dy"].as_f64()), (Some(15.0), Some(0.0)));+ assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, at.x + 15.0, at.y)), vec![Action::Commit]);+ }++ #[test]+ fn selection_tool_grabber_moves_content_elsewhere_moves_the_frame() {+ let mut d = Document::new(&NewDocument::default());+ let f = graphic_frame(&mut d);+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let frame = Selection::items(vec![f]);+ let content = Selection { content: true, ..Selection::items(vec![f]) };+ let centre = spread_pt(&l, 150.0, 150.0);+ let mut t = create("selection");+ // Hovering the grabber shows the hand; it is there on hover before any click, too.+ assert_eq!(t.cursor(&ctx(&d, &Selection::default(), &c, &l), centre, Mods::default()), Cursor::Hand);+ let g = select::grabbers(&ctx(&d, &Selection::default(), &c, &l), Some(centre));+ assert!(matches!(g.as_slice(), [(id, p)] if *id == f && near(*p, centre)), "{g:?}");+ // Press on the grabber: the content is selected; the drag moves it.+ let a = t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Down, centre.x, centre.y));+ assert_eq!(a, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0], "content": true}))]);+ let a = t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Drag, centre.x - 20.0, centre.y + 10.0));+ let p = preview_params(&a);+ assert_eq!((p["dx"].as_f64(), p["dy"].as_f64(), &p["content"]), (Some(-20.0), Some(10.0), &serde_json::json!(true)));+ assert_eq!(t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Up, centre.x - 20.0, centre.y + 10.0)), vec![Action::Commit]);+ // A press elsewhere in the frame keeps the content selection; dragging selects and moves the frame.+ let edge = spread_pt(&l, 115.0, 185.0);+ assert!(t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Down, edge.x, edge.y)).is_empty());+ let a = t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Drag, edge.x + 30.0, edge.y));+ assert_eq!(a[0], Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0]})));+ assert_eq!(a[1], Action::Begin("Move".into()));+ let p = preview_params(&a);+ assert_eq!((p["dx"].as_f64(), p.get("content"), p.get("ids")), (Some(30.0), None, None));+ t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Up, edge.x + 30.0, edge.y));+ // With the frame selected, a drag away from the grabber moves the frame.+ t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Down, edge.x, edge.y));+ let a = t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Drag, edge.x, edge.y + 30.0));+ assert_eq!(a[0], Action::Begin("Move".into()));+ assert_eq!(preview_params(&a).get("content"), None);+ }++ #[test]+ fn double_click_toggles_frame_and_content() {+ let mut d = Document::new(&NewDocument::default());+ let f = graphic_frame(&mut d);+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let at = spread_pt(&l, 120.0, 180.0);+ let mut t = create("selection");- let dbl = PointerEvent::new(PointerKind::DoubleClick, at.x, at.y);+ let frame = Selection::items(vec![f]);- let a = t.pointer(&ctx(&d, &frame, &c, &l), &dbl);- assert_eq!(a, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0], "content": true}))]);+ let content = Selection { content: true, ..Selection::items(vec![f]) };- let a = t.pointer(&ctx(&d, &content, &c, &l), &dbl);++ let set = |content: bool| vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0], "content": content}))];++ // The canvas's presses in a row: the first selects the frame, the second its content.++ let a = t.pointer(&ctx(&d, &Selection::default(), &c, &l), &PointerEvent::new(PointerKind::Down, at.x, at.y));+ assert_eq!(a, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [f.0], "content": false}))]);++ t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Up, at.x, at.y));++ assert_eq!(t.pointer(&ctx(&d, &frame, &c, &l), &PointerEvent::new(PointerKind::Down, at.x, at.y).with_clicks(2)), set(true));++ assert!(t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Up, at.x, at.y)).is_empty());++ // With the content selected, the first press keeps it and the second selects the frame.++ assert!(t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Down, at.x, at.y)).is_empty());++ t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Up, at.x, at.y));++ assert_eq!(t.pointer(&ctx(&d, &content, &c, &l), &PointerEvent::new(PointerKind::Down, at.x, at.y).with_clicks(2)), set(false));++ // A double click sent as such (control channel) toggles too.++ let dbl = PointerEvent::new(PointerKind::DoubleClick, at.x, at.y);++ assert_eq!(t.pointer(&ctx(&d, &frame, &c, &l), &dbl), set(true));++ assert_eq!(t.pointer(&ctx(&d, &content, &c, &l), &dbl), set(false));+ }diff --cc crates/ui-egui/src/canvas.rsindex 09c1bbe10,72098e341..819dfcc89--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -322,8 -315,17 +322,18 @@@ pub fn show(app: &mut DesignApp, ui: &m}}let sel_rect = draw_selection(app, &painter, &xf, &doc, &layout);+ if !preview {+ // Content grabbers: the selected frame's and the hovered one's (Selection tool).+ let hover = ui.ctx().pointer_hover_pos().filter(|p| screen.contains(*p)).map(|p| xf.to_canvas(p));+ let vi = app.view_info();+ for c in app.session.content_grabbers(hover, vi) {+ let c = xf.to_screen(c);+ painter.circle_stroke(c, 8.0, Stroke::new(1.5, Color32::from_white_alpha(170)));+ painter.circle_stroke(c, 4.0, Stroke::new(1.5, Color32::from_white_alpha(170)));+ }+ }draw_tool_overlays(app, &painter, &xf);+ ime_output(app, ui.ctx(), &xf);if rulers {draw_rulers(app, ui, full, rect, &xf, &doc, &layout, &t);ruler_units_menus(app, &resp, full, rect, &doc);