Skip to content

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

Integration: #1125 Direct Selection on one of several selected frames selects just that frame

aiongg09fbe280ffa0
diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs
index 43f36b703..16ccbad0c 100644
--- a/crates/tools/src/select.rs
+++ b/crates/tools/src/select.rs
@@ -789,8 +789,11 @@ impl SelectionTool {
} else {
out.push(Action::Exec("selection.toggle".into(), json!({"id": id.0})));
}
- } else if !cx.selection.contains(id) || (self.direct && !cx.selection.content && cx.doc.item(id).is_some_and(holds_content)) {
- // Direct Selection on a selected frame selects its content (a graphic or pasted-in items).
+ } else if !cx.selection.contains(id)
+ || (self.direct && !cx.selection.content && (cx.selection.items.len() > 1 || cx.doc.item(id).is_some_and(holds_content)))
+ {
+ // Direct Selection on a selected frame selects its content (a graphic or pasted-in items),
+ // and on one of several selected objects just that object.
out.push(Action::Exec("selection.set".into(), json!({"ids": [id.0], "content": self.direct})));
} else if !self.direct && cx.selection.items.len() > 1 {
// InDesign: a click on one of several selected objects makes it the
diff --git a/crates/tools/src/tests.rs b/crates/tools/src/tests.rs
index 94e858092..03a19c73a 100644
--- a/crates/tools/src/tests.rs
+++ b/crates/tools/src/tests.rs
@@ -2069,3 +2069,16 @@ fn loaded_text_cursor_threads_into_a_frame_inside_a_group() {
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);
}
+
+#[test]
+fn direct_selection_click_on_one_of_several_selected_frames_selects_only_it() {
+ let mut d = Document::new(&NewDocument::default());
+ let a = add_rect(&mut d, Rect::new(100.0, 100.0, 200.0, 200.0));
+ let b = add_rect(&mut d, Rect::new(300.0, 100.0, 400.0, 200.0));
+ let (s, c, l) = (Selection::items(vec![a, b]), Cache::new(), CanvasLayout::new(&d, false));
+ let cx = ctx(&d, &s, &c, &l);
+ let p = spread_pt(&l, 150.0, 150.0);
+ let mut t = create("directSelection");
+ let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));
+ assert_eq!(acts, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [a.0], "content": true}))]);
+}