mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 18:54:31 +01:00
Direct Selection: Cmd/Ctrl held lends the Selection tool and shows its bounding box (#3901)
Squashed from #5851 onto main.
This commit is contained in:
1 parent
b976de560d
commit
483de72dbb
5 files changed
+92
-5
No files matched your search
@@ -2757,6 +2757,42 @@ fn cmd_alt_lends_group_selection_while_direct_selection_is_active() {
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 80.0, 80.0).with_mods(cmd_alt), v).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cmd_lends_the_selection_tool_and_its_bounding_box_to_direct_selection() {
|
||||
// #3901: with Direct Selection, Cmd held gives the Selection tool for the press: its cursor,
|
||||
// and its bounding box's handles scale the object; Direct Selection is back on the release.
|
||||
let (none, cmd) = (Mods::default(), Mods { cmd: true, ..Mods::default() });
|
||||
let v = view();
|
||||
let mut s = session();
|
||||
let anchors = json!([{"x": 100, "y": 100}, {"x": 200, "y": 100}, {"x": 200, "y": 200}, {"x": 100, "y": 200}]);
|
||||
let id = NodeId(s.execute("path.create", &json!({"anchors": anchors, "closed": true})).unwrap()["id"].as_u64().unwrap());
|
||||
s.select_tool("directSelection", v).unwrap();
|
||||
assert_eq!(s.lent_tool_id(&none), None);
|
||||
assert_eq!(s.lent_tool_id(&cmd), Some("selection"));
|
||||
// The path selected whole: the bottom-right handle scales it.
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
assert_eq!(s.cursor(Point::new(200.0, 200.0), cmd, v), vectorcraft_tools::Cursor::ResizeNwSe);
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
|
||||
assert_eq!(s.tool_id(), "selection");
|
||||
for at in [250.0, 300.0] {
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, at, at).with_mods(cmd), v).unwrap();
|
||||
}
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 300.0, 300.0).with_mods(cmd), v).unwrap();
|
||||
assert_eq!(s.tool_id(), "directSelection");
|
||||
let b = s.doc().unwrap().doc.node(id).unwrap().geometric_bounds().unwrap();
|
||||
assert!((b.x0 - 100.0).abs() < 1e-6 && (b.x1 - 300.0).abs() < 1e-6 && (b.y1 - 300.0).abs() < 1e-6, "{b:?}");
|
||||
// An anchor selected: a Cmd drag inside moves the whole path and the anchor stays selected.
|
||||
gesture(&mut s, &[(300.0, 300.0)], none);
|
||||
let picked = s.doc().unwrap().selection.anchors.clone();
|
||||
assert!(!picked.is_empty(), "Direct Selection picked the anchor");
|
||||
let before: Vec<_> = path(&s, id).subpaths[0].anchors.iter().map(|a| a.p).collect();
|
||||
gesture(&mut s, &[(150.0, 150.0), (160.0, 160.0), (170.0, 150.0)], cmd);
|
||||
let after: Vec<_> = path(&s, id).subpaths[0].anchors.iter().map(|a| a.p).collect();
|
||||
assert_eq!(after, before.iter().map(|p| *p + kurbo::Vec2::new(20.0, 0.0)).collect::<Vec<_>>());
|
||||
assert_eq!(s.doc().unwrap().selection.anchors, picked, "the anchor is still selected");
|
||||
assert_eq!(s.tool_id(), "directSelection");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pen_drops_the_new_path_asterisk_once_a_path_is_started() {
|
||||
// The Pen's asterisk means a click starts a new path: it shows until the first anchor is
|
||||
|
||||
@@ -154,6 +154,8 @@ impl Session {
|
||||
/// Direct Selection to the tools that edit anchors (the Pen) and Selection to the others.
|
||||
/// Cmd+Alt lends Group Selection while Direct Selection is active. Cmd still lends the last
|
||||
/// selection tool from other tools (Alt on the lent Direct Selection gesture stays copy/subtract).
|
||||
/// Cmd alone lends Direct Selection the Selection tool, whose bounding box transforms the
|
||||
/// object (#3901; <https://community.adobe.com/t5/illustrator-discussions/handles-disappar-on-shape-with-direct-selection-tool/m-p/14848662>).
|
||||
/// Perspective Selection keeps Cmd+Alt drags to copy objects on their perspective plane.
|
||||
/// None for the other selection tools and the view tools.
|
||||
fn lent_tool(&self, id: &str, mods: &Mods) -> Option<&'static str> {
|
||||
@@ -161,8 +163,8 @@ impl Session {
|
||||
if matches!(id, "hand" | "zoom" | "rotateView") {
|
||||
return None;
|
||||
}
|
||||
if id == "directSelection" && mods.cmd && mods.alt {
|
||||
return Some("groupSelection");
|
||||
if id == "directSelection" && mods.cmd {
|
||||
return Some(if mods.alt { "groupSelection" } else { "selection" });
|
||||
}
|
||||
if id == "perspectiveSelection" && mods.cmd && mods.alt {
|
||||
return None;
|
||||
@@ -173,6 +175,16 @@ impl Session {
|
||||
Some(self.last_selection_tool.unwrap_or(if edits_anchors(id) { "directSelection" } else { "selection" }))
|
||||
}
|
||||
|
||||
/// The selection tool a press with `mods` would borrow from the active tool
|
||||
/// ([`Self::lend_selection_tool`]), as [`Self::cursor`] shows it: the canvas also shows what
|
||||
/// that tool shows (Direct Selection with Cmd held shows the bounding box).
|
||||
pub fn lent_tool_id(&self, mods: &Mods) -> Option<&'static str> {
|
||||
if !mods.cmd || self.lender.is_some() {
|
||||
return None;
|
||||
}
|
||||
self.lent_tool(self.tool.id(), mods)
|
||||
}
|
||||
|
||||
/// A press with Cmd held (Ctrl elsewhere) and any other tool than a selection tool: the
|
||||
/// selection tool [`Self::lent_tool`] takes the gesture, pressing without Cmd (a plain click,
|
||||
/// not Select Behind). The tool lent to stays as it was, unaware, until the release.
|
||||
|
||||
Reference in new issue
Block a user