DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Integration (#636): with Direct Selection an anchor under the pointer wins over a type-on-a-path bracket, so the end anchors (where the default brackets sit) can be dragged again
aiongg2732f8c2e605
diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rsindex 7e9fe3270..6338696e4 100644--- a/crates/tools/src/select.rs+++ b/crates/tools/src/select.rs@@ -187,6 +187,15 @@ impl SelectionTool {Self { direct, drag: Drag::None, hover_handle: None, guides: vec![], shift_release: None, loaded: None, live: None }}+ /// [`bracket_at`] for this tool. With Direct Selection an anchor under the pointer wins: the+ /// default brackets sit on the path's end anchors.+ fn bracket_at(&self, cx: &ToolContext, p: Point) -> Option<(ItemId, bool)> {+ if self.direct && anchor_at(cx, p).is_some() {+ return None;+ }+ bracket_at(cx, p)+ }+/// The frame in live-corner editing, while it is still the selection.fn live_corners(&self, cx: &ToolContext) -> Option<LiveFrame> {let id = self.live?;@@ -649,7 +658,7 @@ impl Tool for SelectionTool {self.shift_release = None;// Type on a path: a bracket moves where the text starts or ends.if !ev.mods.shift- && let Some((id, end)) = bracket_at(cx, p)+ && let Some((id, end)) = self.bracket_at(cx, p){self.drag = Drag::Bracket { id, end };return vec![Action::Begin("Move Bracket".into())];@@ -1105,7 +1114,7 @@ impl Tool for SelectionTool {if let Drag::Move { content: true, .. } = self.drag {return Cursor::HandGrab;}- if matches!(self.drag, Drag::Bracket { .. }) || (matches!(self.drag, Drag::None) && bracket_at(cx, p).is_some()) {+ if matches!(self.drag, Drag::Bracket { .. }) || (matches!(self.drag, Drag::None) && self.bracket_at(cx, p).is_some()) {return Cursor::PathBracket;}if self.direct {diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rsindex 770de2164..c35ece5a1 100644--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@ -1638,3 +1638,37 @@ fn the_selection_tool_drags_a_path_type_bracket_along_its_path() {let [Action::Preview(_, p)] = a.as_slice() else { panic!("{a:?}") };assert!((p["end"].as_f64().unwrap() - 350.0).abs() < 1e-6, "{p}");}++#[test]+fn direct_selection_drags_the_end_anchors_of_type_on_a_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() };+ // The default brackets: on the first and last anchors.+ tf.options.path = Some(designcraft_doc::PathType::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 s = Selection { items: vec![id], content: true, ..Default::default() };+ let cx = ctx(&d, &s, &c, &l);+ for (x, end) in [(100.0, false), (500.0, true)] {+ let p = Point::new(x + off.x, 300.0 + off.y);+ let mut direct = create("directSelection");+ assert_ne!(direct.cursor(&cx, p, Mods::default()), Cursor::PathBracket, "anchor at {x}");+ assert_eq!(direct.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y)), vec![Action::Begin("Move Anchor".into())]);+ // The Selection tool still takes the bracket there.+ let mut sel = create("selection");+ assert_eq!(sel.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y)), vec![Action::Begin("Move Bracket".into())], "end {end}");+ }+}