DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge PR #1075: Thread the loaded text cursor into a text frame inside a group
aiongg3021a8f89357
diff --cc crates/tools/src/tests.rsindex 57ef0e53c,9e76e8a8b..bd4382d78--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@@ -1854,6 -1262,105 +1854,55 @@@ fn eyedropper_ignores_inactive_states_olet off = l.xf(SpreadRef::Doc(0)).translation();let cx = ctx(&d2, &s, &c, &l);let a = create("eyedropper").pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0 + off.x, 130.0 + off.y));- assert_eq!(a.contains(&sample), samples, "active state {active}: {a:?}");+ assert_eq!(samples_image(&a), samples, "active state {active}: {a:?}");}}+-#[test]-fn pen_cursor_shows_add_delete_and_close() {- 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, 200.0, 200.0), lid, "", ParaFormat::default()).unwrap();- let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));- let selected = Selection::items(vec![fid]);- let none = Selection::default();- let off = l.xf(SpreadRef::Doc(0)).translation();- let at = |x: f64, y: f64| Point::new(x + off.x, y + off.y);- let mut t = create("pen");- let m = Mods::default();-- let cx = ctx(&d, &selected, &c, &l);- assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::PenDelete, "on a selected path's anchor");- assert_eq!(t.cursor(&cx, at(150.0, 101.0), m), Cursor::PenAdd, "on a selected path's outline");- assert_eq!(t.cursor(&cx, at(150.0, 150.0), m), Cursor::Pen, "inside, away from the outline");- let click = |t: &mut Box<dyn Tool>, cx: &ToolContext, p: Point| {- let down = t.pointer(cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));- let up = t.pointer(cx, &PointerEvent::new(PointerKind::Up, p.x, p.y));- (down, up)- };- let (down, up) = click(&mut t, &cx, at(200.0, 100.0));- assert_eq!(down, vec![Action::Exec("path.deleteAnchor".into(), serde_json::json!({"id": fid.0, "subpath": 0, "anchor": 1}))]);- assert!(up.is_empty() && !t.busy(), "deleting starts no path");- let (down, _) = click(&mut t, &cx, at(150.0, 101.0));- assert!(matches!(&down[..], [Action::Exec(cmd, p)] if cmd == "path.addAnchor" && p["id"] == fid.0), "{down:?}");-- // Unselected paths are drawn over; the first anchor of the path being drawn closes it.- let cx = ctx(&d, &none, &c, &l);- assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::Pen, "unselected path");- click(&mut t, &cx, at(300.0, 300.0));- assert_eq!(t.cursor(&cx, at(300.0, 300.0), m), Cursor::Pen, "one anchor cannot close yet");- click(&mut t, &cx, at(400.0, 300.0));- assert_eq!(t.cursor(&cx, at(301.0, 301.0), m), Cursor::PenClose, "on the first anchor");- assert_eq!(t.cursor(&cx, at(350.0, 350.0), m), Cursor::Pen, "elsewhere while drawing");-}--#[test]-fn anchor_tools_show_pen_state_cursors() {- let d = Document::new(&NewDocument::default());- let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));- let cx = ctx(&d, &s, &c, &l);- let p = Point::new(10.0, 10.0);- let cursor = |id: &str| create(id).cursor(&cx, p, Mods::default());- assert_eq!(cursor("addAnchor"), Cursor::PenAdd);- assert_eq!(cursor("deleteAnchor"), Cursor::PenDelete);- assert_eq!(cursor("convertDirection"), Cursor::PenConvert);-}-+ #[test]+ fn loaded_text_cursor_threads_into_a_frame_inside_a_group() {+ // `hit` stops at the group, so the loaded cursor showed NotAllowed over a text frame inside+ // one and a click did nothing. InDesign threads into it (gaps 27).+ let mut td = thread_doc();+ let lid = td.d.default_layer();+ let rect = Rect::new(600.0, 100.0, 700.0, 200.0);+ // The frame, then the same frame moved inside a group. Both transforms are the identity, so+ // the child's coordinates stay the spread's.+ let (inner, _) = td.d.add_text_frame(SpreadRef::Doc(0), rect, lid, "", ParaFormat::default()).unwrap();+ let frame_item = td.d.item(inner).cloned().unwrap();+ td.d.remove_item(inner).unwrap();+ let gid = ItemId(td.d.alloc());+ let mut group = Item::new(gid, lid, Shape::Group, shapes::rectangle(rect));+ group.content = designcraft_doc::item::Content::Group { items: vec![std::sync::Arc::new(frame_item)] };+ td.d.insert_item(SpreadRef::Doc(0), group, None).unwrap();+ td.l = CanvasLayout::new(&td.d, false);++ let mut t = create("selection");+ let cx = td.cx();+ click(&mut t, &cx, td.port(td.a, true), Mods::default());+ let p = td.at(650.0, 150.0);++ // Selection still reaches the group, which is what a plain click there should pick.+ assert_eq!(cx.hit(p).map(|(_, i)| i), Some(gid));+ // The loaded text cursor reaches the frame inside it.+ assert_eq!(cx.hit_text_frame(p).map(|(_, i)| i), Some(inner), "the frame in the group");+ assert_eq!(t.cursor(&cx, p, Mods::default()), Cursor::ThreadLink);+ // And the click threads to that frame, not to the group.+ assert_eq!(click(&mut t, &cx, p, Mods::default()), thread_exec(serde_json::json!({"from": td.a.0, "to": inner.0})));++ // A group with nothing threadable in it still says no.+ let mut td2 = thread_doc();+ let r2 = Rect::new(600.0, 300.0, 700.0, 400.0);+ let plain = ItemId(td2.d.alloc());+ let child = Item::new(plain, lid, Shape::Rectangle, shapes::rectangle(r2));+ let g2 = ItemId(td2.d.alloc());+ let mut group2 = Item::new(g2, lid, Shape::Group, shapes::rectangle(r2));+ group2.content = designcraft_doc::item::Content::Group { items: vec![std::sync::Arc::new(child)] };+ td2.d.insert_item(SpreadRef::Doc(0), group2, None).unwrap();+ td2.l = CanvasLayout::new(&td2.d, false);+ let cx2 = td2.cx();+ let mut t2 = create("selection");+ click(&mut t2, &cx2, td2.port(td2.a, true), Mods::default());+ let q = td2.at(650.0, 350.0);+ assert_eq!(cx2.hit_text_frame(q).map(|(_, i)| i), None, "no text frame in that group");+ assert_eq!(t2.cursor(&cx2, q, Mods::default()), Cursor::NotAllowed);+ }