Merge pull request #9047 from dotCooCoo/fix/ctrl-lends-selection-tool

Selection: Cmd/Ctrl lends Direct Selection until it is released
This commit is contained in:
BFlat authored and GitHub committed 2026-11-25 11:31:03 +07:00
commit 5158ad606c
25 files changed
+1322 -122

No files matched your search

+1 -1
View File
@@ -219,7 +219,7 @@ pub fn set_live_art(f: LiveArt, inputs: LiveInputs) {
}
/// The registered [`LiveInputs`] now, 0 while nothing is registered.
fn live_inputs() -> u64 {
pub fn live_inputs() -> u64 {
LIVE_ART.get().map_or(0, |(_, inputs)| inputs())
}
+13
View File
@@ -107,6 +107,19 @@ pub struct Session {
/// The selection tool chosen last (Selection, Direct Selection or Group Selection): the one Cmd
/// lends the other tools. None until one is chosen.
pub(crate) last_selection_tool: Option<&'static str>,
/// Direct Selection or Group Selection, whichever was chosen last: the one Cmd lends the
/// Selection tool. None until one is chosen.
pub(crate) last_part_selection_tool: Option<&'static str>,
/// The selection tool Cmd lent the last press, which also takes the double-click or
/// triple-click that follows it, with the uid of the document and the id of the tool it was
/// lent from: a follow-up in another document, after a tool switch (also one back to the same
/// tool) or after the tool starts afresh is not lent. None when the press was not lent.
pub(crate) press_lent: Option<(Option<u64>, &'static str, &'static str)>,
/// The selection tool a Cmd press would borrow at the pointer, as [`Session::hover_tool_at`]
/// or [`Session::cursor`] last found it with Cmd held (None inside when it found none), with
/// the document state, active tool and keys it was found for. None when it was last asked
/// without Cmd.
pub(crate) hover_lent: Option<(tooling::HoverKey, Option<&'static str>)>,
pub(crate) last_view: ViewInfo,
/// The selection tools' measurements for the active document as it is: a pointer move or a
/// cursor asked for again over an unchanged document and selection measures nothing again.
+4
View File
@@ -69,6 +69,9 @@ impl Session {
selection_at_lend: None,
lent_selection: None,
last_selection_tool: None,
last_part_selection_tool: None,
press_lent: None,
hover_lent: None,
last_view: ViewInfo::default(),
preview_memo: Default::default(),
depth: 0,
@@ -211,6 +214,7 @@ impl Session {
return;
}
self.press_type_selection = None;
self.press_lent = None;
let view = self.last_view;
// The edit the tool computes on another thread and the input held for it belong to the
// document being left. The switch goes on whatever they did, as for the deactivation.
+454
View File
@@ -4860,6 +4860,460 @@ 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_direct_selection_or_group_selection_chosen_last() {
// Cmd held with the Selection tool: Direct Selection takes the press until the release, so a
// Cmd-click picks one path inside a group where a plain click picks the group.
let (none, cmd) = (Mods::default(), Mods { cmd: true, ..Mods::default() });
let v = view();
let mut s = session();
let a = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
let b = rect(&mut s, 300.0, 100.0, 100.0, 100.0);
let group = NodeId(s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap()["id"].as_u64().unwrap());
s.execute("select.none", &json!({})).unwrap();
s.select_tool("selection", v).unwrap();
assert_eq!(s.lent_tool_id(&none), None);
assert_eq!(s.lent_tool_id(&cmd), Some("directSelection"));
assert_eq!(s.shown_tool_id(&cmd), "directSelection");
assert_eq!(s.shown_tool_id(&none), "selection");
s.pointer(&PointerEvent::new(PointerKind::Down, 150.0, 150.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "directSelection");
s.pointer(&PointerEvent::new(PointerKind::Up, 150.0, 150.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
let picked = &s.active().unwrap().selection;
assert!(picked.contains(a) && !picked.contains(group), "the Cmd-click picks the path, not its group");
s.execute("select.none", &json!({})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 150.0, 150.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 150.0, 150.0), v).unwrap();
assert!(s.active().unwrap().selection.contains(group), "a plain click picks the group");
// Cmd pressed once a drag is under way lends nothing: the pointer and the named tool stay.
s.pointer(&PointerEvent::new(PointerKind::Down, 600.0, 500.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 650.0, 550.0), v).unwrap();
assert_eq!(s.cursor(Point::new(650.0, 550.0), cmd, v), s.cursor(Point::new(650.0, 550.0), none, v));
assert_eq!(s.shown_tool_id(&cmd), "selection");
s.pointer(&PointerEvent::new(PointerKind::Up, 650.0, 550.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
// Group Selection lends the Selection tool, and once chosen, is what the Selection tool borrows.
s.select_tool("groupSelection", v).unwrap();
assert_eq!(s.lent_tool_id(&cmd), Some("selection"));
s.select_tool("selection", v).unwrap();
assert_eq!(s.lent_tool_id(&cmd), Some("groupSelection"));
s.select_tool("directSelection", v).unwrap();
s.select_tool("selection", v).unwrap();
assert_eq!(s.lent_tool_id(&cmd), Some("directSelection"));
}
#[test]
fn a_cmd_double_click_goes_to_the_tool_the_clicks_went_to() {
// With the Selection tool, Cmd-clicks go to Direct Selection, and so does the double-click
// after them: it does not isolate the group as the Selection tool's double-click would.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let a = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
let b = rect(&mut s, 300.0, 100.0, 100.0, 100.0);
s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.select_tool("selection", v).unwrap();
for kind in [PointerKind::Down, PointerKind::Up, PointerKind::Down, PointerKind::Up, PointerKind::DoubleClick] {
s.pointer(&PointerEvent::new(kind, 150.0, 150.0).with_mods(cmd), v).unwrap();
}
assert_eq!(s.tool_id(), "selection");
assert_eq!(s.doc().unwrap().isolation, None, "Direct Selection's double-click does not isolate the group");
// With Group Selection chosen last, the second click selects the group, and the double-click
// still goes to Group Selection, as both clicks did.
s.select_tool("groupSelection", v).unwrap();
s.select_tool("selection", v).unwrap();
s.execute("select.none", &json!({})).unwrap();
for kind in [PointerKind::Down, PointerKind::Up, PointerKind::Down, PointerKind::Up, PointerKind::DoubleClick] {
s.pointer(&PointerEvent::new(kind, 150.0, 150.0).with_mods(cmd), v).unwrap();
}
assert_eq!(s.doc().unwrap().isolation, None, "Group Selection's double-click does not isolate the group");
s.execute("select.none", &json!({})).unwrap();
// A plain double-click is the Selection tool's: it isolates the group.
for kind in [PointerKind::Down, PointerKind::Up, PointerKind::Down, PointerKind::Up, PointerKind::DoubleClick] {
s.pointer(&PointerEvent::new(kind, 150.0, 150.0), v).unwrap();
}
assert!(s.doc().unwrap().isolation.is_some());
}
#[test]
fn a_cmd_double_click_after_a_tool_switch_goes_to_the_new_tool() {
// With the Selection tool, a Cmd-click on type goes to Direct Selection, and so does the
// Cmd double-click after it, which edits the type. Once another tool is chosen, the
// double-click is that tool's: Group Selection's does not edit the type.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let id = NodeId(s.execute("text.create", &json!({"x": 100, "y": 200, "size": 48, "text": "Type"})).unwrap()["id"].as_u64().unwrap());
let c = s.doc().unwrap().doc.node(id).unwrap().geometric_bounds().unwrap().center();
let clicks = |s: &mut Session, then: Option<&str>| {
s.execute("select.none", &json!({})).unwrap();
s.select_tool("selection", v).unwrap();
for kind in [PointerKind::Down, PointerKind::Up] {
s.pointer(&PointerEvent::new(kind, c.x, c.y).with_mods(cmd), v).unwrap();
}
if let Some(tool) = then {
s.select_tool(tool, v).unwrap();
}
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, c.x, c.y).with_mods(cmd), v).unwrap()
};
assert_eq!(clicks(&mut s, None), [UiRequest::SwitchTool("type".into())], "Direct Selection's double-click edits the type");
assert_eq!(clicks(&mut s, Some("groupSelection")), [], "Group Selection's double-click does not");
assert_eq!(s.tool_id(), "groupSelection");
}
#[test]
fn a_cmd_double_click_after_switching_away_and_back_goes_to_the_active_tool() {
// A Cmd-click with the Selection tool goes to Direct Selection. After a switch to another tool
// and back to the Selection tool, or a fresh start of the tool (another view of the document),
// the Cmd double-click is the Selection tool's: it isolates the group.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let a = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
let b = rect(&mut s, 300.0, 100.0, 100.0, 100.0);
s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap();
for reset in [false, true] {
s.execute("select.none", &json!({})).unwrap();
s.select_tool("selection", v).unwrap();
for kind in [PointerKind::Down, PointerKind::Up] {
s.pointer(&PointerEvent::new(kind, 150.0, 150.0).with_mods(cmd), v).unwrap();
}
if reset {
s.reset_tool();
} else {
s.select_tool("rectangle", v).unwrap();
s.select_tool("selection", v).unwrap();
}
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 150.0, 150.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
assert!(s.doc().unwrap().isolation.is_some(), "the Selection tool's double-click isolates the group (reset: {reset})");
s.execute("object.exitIsolation", &json!({})).unwrap();
}
}
#[test]
fn a_cmd_press_on_a_selected_object_keeps_select_behind() {
// Over a selected object, a Cmd-click with the Selection tool selects the object behind it;
// with Select Behind off, Direct Selection takes the press there too.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
// The canvas shows the marks of the tool a press at the pointer takes, and the status bar and
// the help bar name it.
s.cursor(Point::new(200.0, 200.0), cmd, v);
assert_eq!(s.hover_tool_id(&cmd), "selection");
assert_eq!(s.shown_tool_id(&cmd), "selection", "the press selects behind: nothing is lent");
s.cursor(Point::new(500.0, 500.0), cmd, v);
assert_eq!(s.hover_tool_id(&cmd), "directSelection");
assert_eq!(s.shown_tool_id(&cmd), "directSelection");
// The bounding box's top middle handle, on the middle of the top segment: the press is lent.
assert_eq!(s.hover_tool_at(Some(Point::new(200.0, 150.0)), &cmd, v), "directSelection", "on a box handle");
// Turning Select Behind off changes what the bars name over the selection.
s.cursor(Point::new(200.0, 200.0), cmd, v);
s.prefs.ctrl_click_selects_behind = false;
assert_eq!(s.shown_tool_id(&cmd), "directSelection");
s.prefs.ctrl_click_selects_behind = true;
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(front), "the Cmd-click selects the object behind");
// On a selected object's anchor, Direct Selection takes the press.
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 250.0, 250.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "directSelection");
s.pointer(&PointerEvent::new(PointerKind::Up, 250.0, 250.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
s.prefs.ctrl_click_selects_behind = false;
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "directSelection");
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
}
#[test]
fn a_cmd_press_on_a_wide_strokes_outer_half_selects_behind() {
// Without Use Preview Bounds the bounding box leaves out the outer half of a wide stroke, which
// the Selection tool still hits: a Cmd press there selects the object behind.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
assert!(!s.prefs.use_preview_bounds);
let back = rect(&mut s, 50.0, 50.0, 300.0, 300.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.execute("stroke.set", &json!({"ids": [front.0], "weight": 40})).unwrap();
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
// 15 pt outside the path, on its stroke.
let at = Point::new(200.0, 135.0);
assert_eq!(s.hover_tool_at(Some(at), &cmd, v), "selection", "the press selects behind");
s.pointer(&PointerEvent::new(PointerKind::Down, at.x, at.y).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
s.pointer(&PointerEvent::new(PointerKind::Up, at.x, at.y).with_mods(cmd), v).unwrap();
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(front), "the Cmd-click selects the object behind");
}
#[test]
fn a_cmd_press_on_a_lone_selected_object_is_lent() {
// With nothing behind the selected object, there is nothing to select behind: Direct Selection
// takes the press.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let lone = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [lone.0]})).unwrap();
assert_eq!(s.hover_tool_at(Some(Point::new(200.0, 200.0)), &cmd, v), "directSelection");
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "directSelection");
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
}
#[test]
fn a_layer_effect_that_moves_art_moves_where_a_cmd_press_selects_behind() {
// A layer effect draws the selected object 250 pt to the right of its path, over the object
// behind it: a Cmd press where it is drawn selects behind. A drop shadow there is not hit, so
// the press is lent. Outline view hits the path where it is, and Preview afterwards still finds
// the moved art.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let outline = ViewInfo { outline: true, ..view() };
let drawn = Point::new(450.0, 200.0);
// On both rectangles' top edges, which Outline view hits, away from the box's handles.
let path = Point::new(170.0, 150.0);
for effect in ["distort.transform", "stylize.dropShadow"] {
let mut s = session();
let back = rect(&mut s, 50.0, 150.0, 700.0, 300.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
let layer = s.doc().unwrap().doc.layers[0].id;
let params = if effect == "distort.transform" { json!({"moveH": 250}) } else { json!({"x": 250, "y": 0, "blur": 0}) };
s.execute("effect.apply", &json!({"effect": effect, "params": params, "ids": [layer.0], "item": null})).unwrap();
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
// The back rectangle is drawn moved too, so it is under both points.
if effect == "distort.transform" {
assert_eq!(s.hover_tool_at(Some(path), &cmd, outline), "selection", "Outline view: on the path");
assert_eq!(s.hover_tool_at(Some(drawn), &cmd, v), "selection", "Preview: where the effect draws it");
s.pointer(&PointerEvent::new(PointerKind::Down, drawn.x, drawn.y).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
s.pointer(&PointerEvent::new(PointerKind::Up, drawn.x, drawn.y).with_mods(cmd), v).unwrap();
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(front), "the Cmd-click selects the object behind");
} else {
assert_eq!(s.hover_tool_at(Some(drawn), &cmd, v), "directSelection", "on the shadow");
}
}
}
#[test]
fn repeated_cmd_clicks_select_behind_a_group_whose_member_is_selected() {
// The first Cmd-click on an unselected group lends Direct Selection, which selects the path
// under the pointer. The group holds that selected path, so the next Cmd-click there selects
// the object behind the group.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let a = rect(&mut s, 150.0, 150.0, 40.0, 40.0);
let b = rect(&mut s, 210.0, 150.0, 40.0, 40.0);
let group = NodeId(s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap()["id"].as_u64().unwrap());
s.execute("select.none", &json!({})).unwrap();
s.select_tool("selection", v).unwrap();
let click = |s: &mut Session| {
s.pointer(&PointerEvent::new(PointerKind::Down, 170.0, 170.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 170.0, 170.0).with_mods(cmd), v).unwrap();
};
click(&mut s);
let picked = &s.active().unwrap().selection;
assert!(picked.contains(a) && !picked.contains(group), "the first Cmd-click picks the path");
assert_eq!(s.hover_tool_at(Some(Point::new(170.0, 170.0)), &cmd, v), "selection", "the next press selects behind");
click(&mut s);
// Made quickly, the two clicks are also a double-click, which neither isolates the group nor
// changes what the second click selected, also with Cmd let go before it.
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 170.0, 170.0), v).unwrap();
assert_eq!(s.doc().unwrap().isolation, None);
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(a), "the second Cmd-click selects the object behind the group");
}
#[test]
fn a_double_click_after_a_selection_change_is_not_kept_for_select_behind() {
// A double-click that follows a Cmd-click selecting behind keeps what it selected, but only
// while the document stays as that click left it.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert!(!s.active().unwrap().selection.contains(front), "the Cmd-click selects behind");
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 200.0, 200.0), v).unwrap();
assert!(s.doc().unwrap().isolation.is_some(), "the double-click isolates as any other");
}
#[test]
fn a_double_click_after_the_pointer_moved_away_is_not_kept_for_select_behind() {
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert!(!s.active().unwrap().selection.contains(front), "the Cmd-click selects behind");
s.pointer(&PointerEvent::new(PointerKind::Move, 400.0, 400.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Move, 200.0, 200.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 200.0, 200.0), v).unwrap();
assert!(s.doc().unwrap().isolation.is_some(), "the double-click isolates as any other");
}
#[test]
fn a_double_click_after_a_select_behind_drag_is_not_kept_for_select_behind() {
// A Cmd press that selects behind and then drags is not a click, also when the drag ends where
// it began and moves nothing, so a double-click there is a double-click of its own.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 260.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert!(s.active().unwrap().selection.contains(back), "the Cmd press selects behind");
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 200.0, 200.0), v).unwrap();
assert!(s.doc().unwrap().isolation.is_some(), "the double-click isolates as any other");
}
#[test]
fn a_double_click_after_a_select_behind_press_released_away_is_not_kept_for_select_behind() {
// The automation interface can send the release far from the press with no drag between.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 270.0, 270.0).with_mods(cmd), v).unwrap();
assert!(s.active().unwrap().selection.contains(back), "the Cmd press selects behind");
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 270.0, 270.0), v).unwrap();
assert!(s.doc().unwrap().isolation.is_some(), "the double-click isolates as any other");
}
#[test]
fn a_double_click_in_the_frame_of_a_select_behind_press_keeps_what_it_selected() {
// The second press and the double-click can come in one frame, before the release.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [back.0]})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::DoubleClick, 200.0, 200.0).with_mods(cmd), v).unwrap();
assert_eq!(s.doc().unwrap().isolation, None, "the double-click neither isolates nor edits");
let picked = &s.active().unwrap().selection;
assert!(picked.contains(front) && !picked.contains(back), "the press selects behind, back to the topmost");
}
#[test]
fn a_cmd_click_on_an_unselected_member_of_a_group_holding_the_selection_selects_behind() {
// The group counts as selected wherever its art is, not only over its selected member.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 300.0, 200.0);
let a = rect(&mut s, 150.0, 150.0, 40.0, 40.0);
let b = rect(&mut s, 300.0, 150.0, 40.0, 40.0);
s.execute("object.group", &json!({"ids": [a.0, b.0]})).unwrap();
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [a.0]})).unwrap();
assert_eq!(s.hover_tool_at(Some(Point::new(320.0, 170.0)), &cmd, v), "selection", "on the unselected member");
s.pointer(&PointerEvent::new(PointerKind::Down, 320.0, 170.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 320.0, 170.0).with_mods(cmd), v).unwrap();
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(b), "the Cmd-click selects the object behind the group");
}
#[test]
fn a_cmd_click_on_a_selected_lines_segment_selects_behind() {
// An open, unfilled path is only hit near its segments: a Cmd press there selects the object
// behind it, and a Cmd press on its anchor is Direct Selection's.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
let back = rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = line(&mut s, 150.0, 150.0, 250.0, 250.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
assert_eq!(s.hover_tool_at(Some(Point::new(150.0, 150.0)), &cmd, v), "directSelection", "on its anchor");
// On the segment, away from the anchors and the bounding box's handles.
s.pointer(&PointerEvent::new(PointerKind::Down, 180.0, 180.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
s.pointer(&PointerEvent::new(PointerKind::Up, 180.0, 180.0).with_mods(cmd), v).unwrap();
let picked = &s.active().unwrap().selection;
assert!(picked.contains(back) && !picked.contains(front), "the Cmd-click selects the object behind");
}
#[test]
fn a_hovers_lend_decision_holds_only_for_the_tool_and_selection_it_was_found_for() {
// While the view moves, the canvas reads the last hover's decision: it does not carry over to
// another tool or another selection.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
assert_eq!(s.hover_tool_at(Some(Point::new(200.0, 200.0)), &cmd, v), "selection");
s.execute("select.none", &json!({})).unwrap();
assert_eq!(s.hover_tool_id(&cmd), "directSelection", "nothing is selected now");
assert_eq!(s.hover_tool_at(Some(Point::new(500.0, 500.0)), &cmd, v), "directSelection");
s.select_tool("rectangle", v).unwrap();
assert_eq!(s.hover_tool_id(&cmd), s.lent_tool_id(&cmd).unwrap(), "the new tool's lend");
}
#[test]
fn the_marks_follow_this_frames_pointer_with_cmd_held() {
// The canvas asks which tool's marks to draw before it asks for the cursor: the answer is for
// the pointer where it is now, and with the pointer off the canvas, the tool Cmd lends.
let cmd = Mods { cmd: true, ..Mods::default() };
let v = view();
let mut s = session();
rect(&mut s, 100.0, 100.0, 200.0, 200.0);
let front = rect(&mut s, 150.0, 150.0, 100.0, 100.0);
s.select_tool("selection", v).unwrap();
s.execute("select.set", &json!({"ids": [front.0]})).unwrap();
s.cursor(Point::new(200.0, 200.0), cmd, v);
assert_eq!(s.hover_tool_id(&cmd), "selection");
assert_eq!(s.hover_tool_at(Some(Point::new(500.0, 500.0)), &cmd, v), "directSelection", "away from the selection");
assert_eq!(s.hover_tool_at(Some(Point::new(200.0, 200.0)), &cmd, v), "selection", "over the selection");
assert_eq!(s.hover_tool_at(None, &cmd, v), "directSelection", "off the canvas");
assert_eq!(s.hover_tool_id(&cmd), "directSelection", "kept while the view moves");
assert_eq!(s.hover_tool_at(None, &Mods::default(), v), "selection", "without Cmd");
}
#[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,
@@ -1212,6 +1212,26 @@ fn select_part_refuses_hidden_and_locked_objects_of_the_art() {
s.execute("symbol.instance.selectPart", &json!({"id": inst.0, "path": [1, 1]})).unwrap();
}
#[test]
fn a_cmd_click_with_the_selection_tool_keeps_the_instance_selected_whole() {
// Cmd lends Direct Selection the Selection tool: the press picks one object of a dynamic
// instance, and back with the Selection tool after the release, the instance stays selected,
// whole, as choosing the Selection tool leaves it.
let mut s = session();
let inst = pair(&mut s, "dynamic");
let v = ViewInfo { smart_guides: false, ..Default::default() };
let cmd = Mods { cmd: true, ..Mods::default() };
s.select_tool("selection", v).unwrap();
s.execute("select.none", &json!({})).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Down, 80.0, 30.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "directSelection");
assert!(s.doc().unwrap().selection.symbol_part.is_some(), "the lent tool picks the object");
s.pointer(&PointerEvent::new(PointerKind::Up, 80.0, 30.0).with_mods(cmd), v).unwrap();
assert_eq!(s.tool_id(), "selection");
let sel = &s.doc().unwrap().selection;
assert_eq!((&sel.objects, &sel.symbol_part), (&vec![inst], &None));
}
#[test]
fn choosing_the_selection_tool_again_picks_the_instance_whole() {
let mut s = session();
+156 -12
View File
@@ -10,6 +10,25 @@ use vectorcraft_tools::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind
use crate::{EngineError, Prefs, Result, Session};
/// What a hover's lend decision holds for ([`Session::hover_tool_at`]).
#[derive(Clone, Copy, PartialEq)]
pub(crate) struct HoverKey {
/// The active document's uid and revision, which moves with the selection.
doc: Option<(u64, u64)>,
tool: &'static str,
mods: Mods,
/// The selection tool and the part selection tool chosen last.
last_tools: (Option<&'static str>, Option<&'static str>),
ctrl_click_selects_behind: bool,
object_selection_by_path_only: bool,
type_selection_by_path_only: bool,
selection_tolerance: f64,
anchor_size: u32,
use_preview_bounds: bool,
type_glyph_bounds: bool,
show_handles_multiple_anchors: bool,
}
/// The tool whose radius is General › Corner Radius.
const ROUNDED_RECTANGLE: &str = "roundedRectangle";
@@ -183,6 +202,9 @@ impl Session {
if self.tool.id() == id {
return Ok(());
}
// A double-click or triple-click after the switch is the new tool's, also when the switch
// comes back to the tool a Cmd press was lent from.
self.press_lent = None;
// Sampling type keeps its highlighted characters as the target, and a whole story that
// Select All selected. Capture before the Type tool deactivates (which commits typing and
// clears its editing state).
@@ -208,6 +230,9 @@ impl Session {
}
if vectorcraft_tools::catalog::is_selection_tool(id) {
self.last_selection_tool = Some(self.tool.id());
if id != "selection" {
self.last_part_selection_tool = Some(self.tool.id());
}
self.select_whole_instance(id);
}
Ok(())
@@ -251,8 +276,10 @@ impl Session {
/// 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>).
/// Group Selection lends the Selection tool, and the Selection tool lends Direct Selection or
/// Group Selection, whichever was chosen last (Direct Selection until one is).
/// Perspective Selection keeps Cmd+Alt drags to copy objects on their perspective plane.
/// None for the other selection tools and the view tools.
/// None for the view tools.
fn lent_tool(&self, id: &str, mods: &Mods) -> Option<&'static str> {
use vectorcraft_tools::catalog::{edits_anchors, is_selection_tool};
if matches!(id, "hand" | "zoom" | "rotateView") {
@@ -261,6 +288,12 @@ impl Session {
if id == "directSelection" && mods.cmd {
return Some(if mods.alt { "groupSelection" } else { "selection" });
}
if id == "groupSelection" && mods.cmd {
return Some("selection");
}
if id == "selection" && mods.cmd {
return Some(self.last_part_selection_tool.unwrap_or("directSelection"));
}
if id == "perspectiveSelection" && mods.cmd && mods.alt {
return None;
}
@@ -280,15 +313,118 @@ impl Session {
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. → the event
/// for the tool, and the warnings of a preview that keeping the typing applied.
fn lend_selection_tool(&mut self, ev: &PointerEvent) -> Result<(PointerEvent, Vec<String>)> {
if ev.kind != PointerKind::Down || !ev.mods.cmd || self.lender.is_some() {
/// The tool the status bar and the help bar name with `mods` held: the selection tool Cmd
/// lends ([`Self::lent_tool_id`]) while the button is up, Space does not lend a view tool and
/// the active tool is not computing an edit, else the active tool. Over a selected object where
/// a Cmd press selects behind, as the cursor last found it, it names the active tool.
pub fn shown_tool_id(&self, mods: &Mods) -> &'static str {
match self.hovered_lent(mods) {
Some(id) if !mods.space && !self.tool_editing() && !self.pointer_held => id,
_ => self.tool.id(),
}
}
/// The tool whose marks the canvas shows with `mods` held: the selection tool a Cmd press at
/// the pointer would borrow, as [`Self::hover_tool_at`] or [`Self::cursor`] last found it
/// (before either has, the one [`Self::lent_tool_id`] names), else the active tool. The canvas
/// asks this while the view moves, when it does not hit-test the art under the pointer.
pub fn hover_tool_id(&self, mods: &Mods) -> &'static str {
match self.hovered_lent(mods) {
Some(id) if mods.cmd && !mods.space && self.lender.is_none() && !self.tool_editing() && !self.pointer_held => id,
_ => self.tool.id(),
}
}
/// The selection tool a Cmd press with `mods` would borrow at the pointer: the one
/// [`Self::hover_tool_at`] or [`Self::cursor`] last found, while the document, the selection,
/// the active tool and the keys are as they were then (none where the press selects behind),
/// else the one [`Self::lent_tool_id`] names.
fn hovered_lent(&self, mods: &Mods) -> Option<&'static str> {
match self.hover_lent {
Some((key, lent)) if key == self.hover_key(mods) => lent,
_ => self.lent_tool_id(mods),
}
}
/// What a hover's lend decision holds for: the active document's state (its uid and revision,
/// which moves with the selection), the active tool, the keys, the selection tools chosen last
/// and the preferences a press's hit test reads.
fn hover_key(&self, mods: &Mods) -> HoverKey {
let p = &self.prefs;
HoverKey {
doc: self.active().map(|d| (d.uid, d.revision)),
tool: self.tool.id(),
mods: *mods,
last_tools: (self.last_selection_tool, self.last_part_selection_tool),
ctrl_click_selects_behind: p.ctrl_click_selects_behind,
object_selection_by_path_only: p.object_selection_by_path_only,
type_selection_by_path_only: p.type_selection_by_path_only,
selection_tolerance: p.selection_tolerance,
anchor_size: p.anchor_size,
use_preview_bounds: p.use_preview_bounds,
type_glyph_bounds: p.type_glyph_bounds,
show_handles_multiple_anchors: p.show_handles_multiple_anchors,
}
}
/// The tool whose marks and widgets the canvas draws this frame with `mods` held and the
/// pointer at `p` (None off the canvas): the selection tool a Cmd press there would borrow
/// ([`Self::lent_tool_at`]; off the canvas, the one [`Self::lent_tool_id`] names), else the
/// active tool. [`Self::hover_tool_id`] then answers the same until the pointer or the keys move.
pub fn hover_tool_at(&mut self, p: Option<Point>, mods: &Mods, view: ViewInfo) -> &'static str {
let lends = mods.cmd && !mods.space && self.lender.is_none() && !self.tool_editing() && !self.pointer_held;
let lent = match p {
_ if !lends => None,
Some(p) => self.lent_tool_at(p, mods, view),
None => self.lent_tool_id(mods),
};
let key = self.hover_key(mods);
self.hover_lent = lends.then_some((key, lent));
lent.unwrap_or(self.tool.id())
}
/// The selection tool a press at `p` with `mods` borrows ([`Self::lent_tool`]): none when
/// the Selection tool keeps a Cmd press on a selected object to select the object behind it
/// (Selection & Anchor Display › Command Click to Select Objects Behind).
fn lent_tool_at(&mut self, p: Point, mods: &Mods, view: ViewInfo) -> Option<&'static str> {
let id = self.lent_tool(self.tool.id(), mods)?;
let behind = self.tool.id() == "selection" && self.with_tool_cx(view, |_, cx| vectorcraft_tools::select::selects_behind_at(cx, p));
(!behind).then_some(id)
}
/// Is the press `ev` lent a selection tool ([`Self::lend_selection_tool`])? The frontend asks
/// before the press, to tell a gesture of the tool in hand from one of a lent tool.
pub fn press_lends_tool(&mut self, ev: &PointerEvent, view: ViewInfo) -> bool {
ev.kind == PointerKind::Down && ev.mods.cmd && self.lender.is_none() && self.lent_tool_at(ev.pos, &ev.mods, view).is_some()
}
/// A press with Cmd held (Ctrl elsewhere): the selection tool [`Self::lent_tool_at`] names
/// takes the gesture, pressing without Cmd (a plain click, not Select Behind). The tool lent to
/// stays as it was, unaware, until the release. With a selection tool active, the double-click
/// or triple-click that follows Cmd-clicks goes to the tool the clicks went to, with Cmd kept
/// (Cmd+Shift releases a guide), and that tool is given back after it. → the event for the tool,
/// and the warnings of a preview that keeping the typing applied.
fn lend_selection_tool(&mut self, ev: &PointerEvent, view: ViewInfo) -> Result<(PointerEvent, Vec<String>)> {
let follow_up =
matches!(ev.kind, PointerKind::DoubleClick | PointerKind::TripleClick) && vectorcraft_tools::catalog::is_selection_tool(self.tool.id());
if ev.kind == PointerKind::Down {
self.press_lent = None;
}
if (ev.kind != PointerKind::Down && !follow_up) || !ev.mods.cmd || self.lender.is_some() {
return Ok((*ev, vec![]));
}
let Some(id) = self.lent_tool(self.tool.id(), &ev.mods) else { return Ok((*ev, vec![])) };
// A follow-up goes where the press before it went, whatever that press selected, while the
// document and the active tool are the ones that press found.
let at = (self.active().map(|d| d.uid), self.tool.id());
let id = if follow_up {
self.press_lent.filter(|(doc, tool, _)| (*doc, *tool) == at).map(|(.., id)| id)
} else {
self.lent_tool_at(ev.pos, &ev.mods, view)
};
let Some(id) = id else { return Ok((*ev, vec![])) };
if !follow_up {
self.press_lent = Some((at.0, at.1, id));
}
// Typing in progress is kept as its own step first: the lent tool's drag previews from the
// document its interaction started from, which would drop the typing (#1881). When it
// can't be kept, the press is not lent.
@@ -316,7 +452,8 @@ impl Session {
}
self.selection_at_lend = self.active().map(|d| (d.uid, d.selection.clone()));
self.lender = Some(std::mem::replace(&mut self.tool, lent));
Ok((PointerEvent { mods: Mods { cmd: false, ..ev.mods }, ..*ev }, settled))
let cmd = follow_up && ev.mods.cmd;
Ok((PointerEvent { mods: Mods { cmd, ..ev.mods }, ..*ev }, settled))
}
/// The lent selection tool's gesture is over: the tool it was lent to is back as it was (the
@@ -341,6 +478,9 @@ impl Session {
self.back_to_bucket = outer_bucket;
self.keep_tool_settings();
self.tool = lender;
// Back with the Selection or Group Selection tool, a symbol part the lent Direct
// Selection picked gives way to its instance, as choosing the tool does.
self.select_whole_instance(self.tool.id());
if let Some(points) = mesh_points {
self.tool.set_option("meshPoints", &points);
}
@@ -771,7 +911,7 @@ impl Session {
}
self.leave_draw_inside(ev, view)?;
self.tell_tool_history_moved();
let (ev, settled) = self.lend_selection_tool(ev)?;
let (ev, settled) = self.lend_selection_tool(ev, view)?;
let ev = &ev;
let lent = self.lender.is_some();
let mut acts = self.with_tool_cx(view, |t, cx| t.pointer(cx, ev));
@@ -795,7 +935,7 @@ impl Session {
PointerKind::Up => self.press_point = None,
_ => {}
}
if ev.kind == PointerKind::Up {
if ev.kind == PointerKind::Up || (lent && matches!(ev.kind, PointerKind::DoubleClick | PointerKind::TripleClick)) {
self.give_back_tool(view)?;
}
r
@@ -1305,7 +1445,11 @@ impl Session {
/// press would borrow ([`Self::lend_selection_tool`]).
pub fn cursor(&mut self, p: Point, mods: Mods, view: ViewInfo) -> Cursor {
// While an edit is computed, a Cmd press is held for the active tool, which shows it is busy.
let lent = if mods.cmd && self.lender.is_none() && !self.tool_editing() { self.lent_tool(self.tool.id(), &mods) } else { None };
// Cmd pressed once a drag is under way lends nothing, so the tool keeps its pointer.
let lends = mods.cmd && self.lender.is_none() && !self.tool_editing() && !self.pointer_held;
let lent = if lends { self.lent_tool_at(p, &mods, view) } else { None };
let key = self.hover_key(&mods);
self.hover_lent = lends.then_some((key, lent));
match lent {
Some(id) => {
let lent = self.make_tool(id);
+68 -9
View File
@@ -385,23 +385,26 @@ pub(crate) fn in_scope(doc: &vectorcraft_doc::Document, scope: Option<NodeId>, i
/// shapes, its first child, are left out unless they are the isolated object (Construction mode),
/// as clicks leave them out.
fn walk_pickable<'a>(doc: &'a vectorcraft_doc::Document, scope: Option<NodeId>, mut f: impl FnMut(&'a Node)) {
fn walk<'a>(n: &'a Node, f: &mut impl FnMut(&'a Node)) {
f(n);
for c in n.children().into_iter().flatten().skip(usize::from(n.extras().shaper.is_some())) {
walk(c, f);
}
}
if let Some(id) = scope
&& let Some(n) = doc.node(id)
{
walk(n, &mut f);
walk_pickable_from(n, &mut f);
} else if scope.is_none() {
for l in &doc.layers {
walk(l, &mut f);
walk_pickable_from(l, &mut f);
}
}
}
/// Visit `n` and the nodes inside it that Direct Selection may pick: a Shaper Group's original
/// shapes are left out ([`walk_pickable`]).
fn walk_pickable_from<'a>(n: &'a Node, f: &mut impl FnMut(&'a Node)) {
f(n);
for c in n.children().into_iter().flatten().skip(usize::from(n.extras().shaper.is_some())) {
walk_pickable_from(c, f);
}
}
/// The spines of the editable blends, topmost first: (blend, spine).
pub(crate) fn spines(cx: &ToolContext) -> Vec<(NodeId, PathData)> {
let mut v = vec![];
@@ -441,7 +444,12 @@ fn hit_spine_point(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, usiz
/// The segment of a selected blend's spine passing within `tol` of `p`: (blend, segment, t, whether
/// it is straight).
pub(crate) fn hit_spine_segment(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, usize, f64, bool)> {
selected_spines(cx).into_iter().find_map(|(id, path)| {
spine_segment_in(&selected_spines(cx), p, tol)
}
/// [`hit_spine_segment`] over spines already built.
fn spine_segment_in(spines: &[(NodeId, PathData)], p: Point, tol: f64) -> Option<(NodeId, usize, f64, bool)> {
spines.iter().find_map(|&(id, ref path)| {
let (si, seg, t, _, dist) = path.nearest(p)?;
(dist <= tol).then(|| (id, seg, t, path.subpaths.get(si).is_some_and(|sp| sp.segment_is_line(seg))))
})
@@ -594,6 +602,57 @@ fn hit_anchor(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, usize, us
})
}
/// Is `p` on a point of a selected object that Direct Selection edits: a gradient mesh point, a
/// blend's spine point or segment, an anchor or the end of a direction handle, within the
/// selection tolerance? A selected group or compound path counts through the editable paths
/// inside it. A path's segments do not count: a Cmd press there with Select Behind on selects
/// the object behind, which a stroke-only path can only be pressed on.
pub fn over_selected_part(cx: &ToolContext, p: Point) -> bool {
if cx.selection.objects.is_empty() {
return false;
}
let tol = cx.point_tol();
let seg_tol = cx.pick_tol();
if hit_handle(cx, p, tol).is_some() || MeshEdit::default().hit(cx, &cx.selection.objects, p).is_some() {
return true;
}
// The selected blends' spines are built once for both of their checks.
let spines = selected_spines(cx);
if spines.iter().any(|(_, path)| path.anchors().any(|(_, _, a)| a.p.distance(p) <= tol)) || spine_segment_in(&spines, p, seg_tol).is_some() {
return true;
}
// The editable paths' control bounds are listed once per document state and selection; a
// hover measures only the paths whose bounds it is near.
let boxes = crate::select::selected_part_boxes(cx, || {
let editable = cx.doc.editable();
let mut v = vec![];
for root in cx.selection.objects.iter().filter_map(|&id| cx.doc.node(id)) {
walk_pickable_from(root, &mut |n| {
if editable(n.id)
&& let Some(b) = editable_path(n).and_then(|pd| pd.control_bounds())
{
v.push((n.id, b));
}
});
}
v.into()
});
boxes.iter().any(|&(id, b)| {
b.inflate(tol, tol).contains(p)
&& cx.doc.node(id).and_then(editable_path).is_some_and(|pd| {
#[cfg(test)]
MEASURED_PARTS.set(MEASURED_PARTS.get() + 1);
nearest_anchor(&pd, p, tol, None).is_some()
})
})
}
#[cfg(test)]
thread_local! {
/// How many paths [`over_selected_part`] has measured on this thread.
static MEASURED_PARTS: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
}
/// Is `p` within a press's reach of an anchor of type on a path's path? The anchor wins over a
/// bracket standing on it (the end bracket on the last anchor, #3980); the bracket's stem above it
/// still drags the bracket.
+54
View File
@@ -2795,3 +2795,57 @@ fn a_marquee_skips_the_anchors_and_segments_of_guides_that_cannot_be_picked() {
assert!(!crossed(&marquee(false, (140.0, 80.0), (160.0, 120.0))), "locked or hidden: no segment");
assert!(crossed(&marquee(true, (140.0, 80.0), (160.0, 120.0))), "shown and unlocked");
}
/// A hover over a large selected group measures only the paths near the pointer when it asks
/// whether a Cmd press there lands on a part Direct Selection edits.
#[test]
fn over_selected_part_measures_only_the_paths_near_the_pointer() {
use vectorcraft_doc::{Appearance, Node};
let mut d = vectorcraft_doc::Document::new(2000.0, 2000.0);
let l = d.layers[0].id;
let squares: Vec<std::sync::Arc<Node>> = (0..400)
.map(|i| {
let (x, y) = (f64::from(i % 20) * 50.0, f64::from(i / 20) * 50.0);
let r = vectorcraft_geom::shapes::rectangle(Rect::new(x, y, x + 20.0, y + 20.0));
std::sync::Arc::new(Node::path(d.alloc_id(), r, Appearance::default_art()))
})
.collect();
let g = d.alloc_id();
d.insert(Some(l), 0, Node::group(g, squares)).unwrap();
let p = paint();
let mut picked = Selection::default();
picked.add(g);
let c = cx(&d, &picked, &p);
let before = MEASURED_PARTS.get();
assert!(over_selected_part(&c, Point::new(520.0, 520.0)), "on a square's corner");
assert!(!over_selected_part(&c, Point::new(535.0, 535.0)), "between the squares");
let measured = MEASURED_PARTS.get() - before;
assert!(measured < 10, "{measured} of 400 paths measured");
}
/// The cursor, the canvas marks and a press each ask whether a Cmd press at the pointer selects
/// behind: while the document and the selection stay as they are, the selection's paths are
/// measured once for a point.
#[test]
fn select_behind_is_measured_once_for_a_point() {
use vectorcraft_doc::{Appearance, Node};
let mut d = vectorcraft_doc::Document::new(400.0, 400.0);
let l = d.layers[0].id;
let id = d.alloc_id();
let square = vectorcraft_geom::shapes::rectangle(Rect::new(100.0, 100.0, 200.0, 200.0));
d.insert(Some(l), 0, Node::path(id, square, Appearance::default_art())).unwrap();
// Below it, an object to select behind.
let back = vectorcraft_geom::shapes::rectangle(Rect::new(50.0, 50.0, 250.0, 250.0));
let back_id = d.alloc_id();
d.insert(Some(l), 0, Node::path(back_id, back, Appearance::default_art())).unwrap();
let p = paint();
let mut picked = Selection::default();
picked.add(id);
let memo = crate::select::PreviewMemo::default();
let c = ToolContext { preview_memo: Some(&memo), select_behind: true, ..cx(&d, &picked, &p) };
let at = Point::new(150.0, 150.0);
let before = MEASURED_PARTS.get();
assert!(crate::select::selects_behind_at(&c, at), "inside the selected square, away from its anchors");
assert!(crate::select::selects_behind_at(&c, at));
assert_eq!(MEASURED_PARTS.get() - before, 1, "measured for the first ask only");
}
+240 -5
View File
@@ -214,6 +214,11 @@ pub struct SelectionTool {
/// Where the pointer was at the last press or drag: a widget drag released anywhere else is
/// dragged there before it ends.
held_at: Option<Point>,
/// Where the last press that selected the object behind (Cmd/Ctrl-click) was released: a
/// double-click there that follows it is that press clicked again, not a double-click that
/// isolates or edits. It holds the document's revision at the release too (None until then),
/// and an edit or a selection change after it ends it.
pressed_behind: Option<(Point, Option<(u64, u64)>)>,
}
/// What Distance Guides measure the selection to.
@@ -503,16 +508,67 @@ struct MemoState {
/// The measurements for one key; a slot holds `None` until it is measured.
struct Measured {
revision: (u64, u64),
/// The fonts, hyphenation exceptions and plug-ins live art is drawn and hit with
/// ([`vectorcraft_doc::hit::live_inputs`]).
live: u64,
objects: Vec<NodeId>,
measure: vectorcraft_effects::preview::Measure,
bounds: Option<Option<Rect>>,
oriented: Option<Option<OrientedBox>>,
by_object: HashMap<NodeId, Option<Option<Rect>>>,
/// [`painted_bounds`] in Preview and in Outline view.
painted: [Option<Option<Rect>>; 2],
/// [`selected_part_boxes`].
part_boxes: Option<std::sync::Arc<[(NodeId, Rect)]>>,
/// [`selection_holders`].
holders: Option<std::sync::Arc<std::collections::HashSet<NodeId>>>,
/// [`selects_behind_at`]'s last answer, with the point and settings it was for.
behind: Option<(BehindKey, bool)>,
}
/// What [`selects_behind_at`] answers for besides the document and the selection: the point, the
/// tolerances (the zoom and the preferences) and the hit-test settings.
#[derive(Clone, Copy, PartialEq)]
struct BehindKey {
at: Point,
pick_tol: f64,
point_tol: f64,
scope: Option<NodeId>,
outline: bool,
path_only: bool,
type_path_only: bool,
skip_guides: bool,
handles_multiple: bool,
/// The zoom, which sets the mesh points' and the box handles' reach.
zoom: f64,
show_bbox: bool,
}
impl BehindKey {
fn of(cx: &ToolContext, at: Point) -> Self {
let opt = cx.selection_hit_options();
Self {
at,
pick_tol: cx.pick_tol(),
point_tol: cx.point_tol(),
scope: cx.isolation,
outline: opt.outline,
path_only: opt.path_only,
type_path_only: opt.type_path_only,
skip_guides: opt.skip_guides,
handles_multiple: cx.handles_multiple,
zoom: cx.zoom,
show_bbox: cx.show_bbox,
}
}
}
impl Measured {
fn is_for(&self, cx: &ToolContext) -> bool {
self.revision == cx.revision && self.measure == cx.bounds_measure() && self.objects == cx.selection.objects
self.revision == cx.revision
&& self.live == vectorcraft_doc::hit::live_inputs()
&& self.measure == cx.bounds_measure()
&& self.objects == cx.selection.objects
}
}
@@ -534,11 +590,16 @@ impl PreviewMemo {
st.checks += 1;
let fresh = || Measured {
revision: cx.revision,
live: vectorcraft_doc::hit::live_inputs(),
objects: cx.selection.objects.clone(),
measure: cx.bounds_measure(),
bounds: None,
oriented: None,
by_object: HashMap::new(),
painted: [None, None],
part_boxes: None,
holders: None,
behind: None,
};
if !st.entry.as_ref().is_some_and(|m| m.is_for(cx)) {
st.entry = Some(fresh());
@@ -553,10 +614,16 @@ impl PreviewMemo {
{
return v;
}
let live = vectorcraft_doc::hit::live_inputs();
let v = measure();
// Live inputs that changed while it measured leave the value unkept: only the entry for the
// inputs it was measured with takes it.
if let Ok(mut st) = self.0.try_borrow_mut() {
st.measurements += 1;
*slot(Self::current(&mut st, cx)) = Some(v.clone());
let m = Self::current(&mut st, cx);
if m.live == live {
*slot(m) = Some(v.clone());
}
}
v
}
@@ -584,6 +651,48 @@ pub fn selection_box(cx: &ToolContext) -> Option<OrientedBox> {
remembered(cx, |m| &mut m.oriented, || vectorcraft_effects::preview::oriented_bounds_with(cx.doc, &cx.selection.objects, cx.bounds_measure()))
}
/// The bounds a hit test can find the objects in that a click selects for the selected art
/// ([`top_holder`]): their reach (a blend's spine included), their visual bounds as drawn
/// (strokes and effects included, whatever Use Preview Bounds says) and their geometric bounds
/// (where Outline view hits the paths), together, kept for each view mode.
fn painted_bounds(cx: &ToolContext) -> Option<Rect> {
let outline = cx.selection_hit_options().outline;
remembered(
cx,
|m| &mut m.painted[usize::from(outline)],
|| {
let mut seen = std::collections::HashSet::new();
let tops: Vec<NodeId> = cx.selection.objects.iter().map(|&id| top_holder(cx, id)).filter(|id| seen.insert(*id)).collect();
// A layer or group above them with visible effects of its own that draw art (not raster
// effects, which a hit test leaves out, nor color adjustments) can draw (and hit) them
// anywhere. Outline view hits the paths where they are.
let moves_art = |e: &vectorcraft_doc::Effect| {
e.visible && !outline && !vectorcraft_effects::is_raster(&e.id) && !vectorcraft_effects::is_adjustment(&e.id)
};
let above_has_effects = tops.iter().any(|id| {
cx.doc.ancestry(*id).is_some_and(|a| {
a.iter().take_while(|n| *n != id).any(|n| cx.doc.node(*n).is_some_and(|n| n.appearance.effects.iter().any(moves_art)))
})
});
if above_has_effects {
return Some(Rect::new(f64::NEG_INFINITY, f64::NEG_INFINITY, f64::INFINITY, f64::INFINITY));
}
let symbols = cx.doc.symbol_boxes();
let reach = tops.iter().filter_map(|id| cx.doc.node(*id)).filter_map(|n| n.reach_bounds_with(&symbols));
let drawn = vectorcraft_effects::preview::bounds_of(cx.doc, &tops, true);
let geometric = vectorcraft_effects::preview::bounds_of(cx.doc, &tops, false);
reach.chain(drawn).chain(geometric).reduce(|a, b| a.union(b))
},
)
}
/// `measure`'s list of the selected objects' editable paths with their control bounds, kept in the
/// session's [`PreviewMemo`] while the document and the selection stay as they are
/// ([`crate::direct::over_selected_part`]).
pub(crate) fn selected_part_boxes(cx: &ToolContext, measure: impl FnOnce() -> std::sync::Arc<[(NodeId, Rect)]>) -> std::sync::Arc<[(NodeId, Rect)]> {
remembered(cx, |m| &mut m.part_boxes, measure)
}
/// [`selection_box`] while the canvas shows it (View › Show Bounding Box, and no anchors selected
/// on their own): its handles take a press only then. A path the Pen is drawing keeps its end
/// anchor selected, so Cmd/Ctrl lending the Selection tool doesn't scale it by hidden handles (#4980).
@@ -804,6 +913,25 @@ impl SelectionTool {
}
}
/// Each press, whatever takes it, starts with no Select Behind of its own, and the double-click
/// that follows one comes where that press is released, with the document as the release left
/// it, before the pointer moves away; a press that drags or is released away is not a click
/// ([`Self::pressed_behind`]).
fn note_pressed_behind(&mut self, cx: &ToolContext, ev: &PointerEvent) {
match ev.kind {
PointerKind::Down => self.pressed_behind = None,
PointerKind::Move | PointerKind::Drag => {
if self.pressed_behind.is_some_and(|(at, _)| at.distance(ev.pos) > cx.tol(1.0)) {
self.pressed_behind = None;
}
}
PointerKind::Up => {
self.pressed_behind = self.pressed_behind.filter(|(at, _)| at.distance(ev.pos) <= cx.tol(1.0)).map(|_| (ev.pos, Some(cx.revision)));
}
_ => {}
}
}
/// Notes where a press or a drag last held the pointer, and says whether a release lands
/// somewhere else.
fn note_held_at(&mut self, ev: &PointerEvent) -> bool {
@@ -1031,10 +1159,16 @@ impl Tool for SelectionTool {
}
}
/// A press lent to another tool is not a Select Behind press of this tool.
fn press_elsewhere(&mut self) {
self.pressed_behind = None;
}
/// A press takes the selection's widgets, a ruler guide, a selected object's centre point or
/// the art; the drags then move, scale, rotate, marquee or drag what it took.
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
self.note_loaded_at_press(ev.kind);
self.note_pressed_behind(cx, ev);
let released_away = self.note_held_at(ev);
let hovering = ev.kind == PointerKind::Move && matches!(self.state, State::Idle);
self.bracket_hover = hovering.then_some(ev.pos);
@@ -1088,6 +1222,7 @@ impl Tool for SelectionTool {
{
self.state =
State::Moving { start: p, press: p, hold: p, grip: Grip::Point, began: false, deselect: None, key: None, exclude: None };
self.pressed_behind = Some((p, None));
return vec![Action::Exec("select.set".into(), json!({ "ids": [behind.0] }))];
}
let (hit, scope) = match selected_source_hit(cx, p) {
@@ -1434,11 +1569,103 @@ impl Tool for SelectionTool {
}
}
/// Select Behind: of the objects under `p` (topmost first), the one below the lowest selected
/// one, back to the topmost after the bottom one; the topmost when none is selected.
/// Does a Cmd/Ctrl press at `p` with the Selection tool select behind: is Select Behind on and an
/// object under the pointer selected or holding selected art (a group with a selected member),
/// with another object under the pointer too, away from the anchors, handles, mesh points and
/// spine Direct Selection edits ([`crate::direct::over_selected_part`])? Elsewhere Cmd lends the
/// press to Direct Selection or Group Selection.
pub fn selects_behind_at(cx: &ToolContext, p: Point) -> bool {
if !cx.select_behind {
return false;
}
let tol = cx.pick_tol();
// The answer is kept for the document and the selection as they are: the cursor, the canvas
// marks and a press at the same point ask again without walking the document again.
let key = BehindKey::of(cx, p);
if let Some(memo) = cx.preview_memo
&& let Ok(mut st) = memo.0.try_borrow_mut()
&& let Some((k, v)) = PreviewMemo::current(&mut st, cx).behind
&& k == key
{
return v;
}
// The painted bounds of the objects holding the selection come first: away from them, no
// document walk is needed. They take in a wide stroke's outer half, which the bounding box
// leaves out without Use Preview Bounds, and a group's members that are not selected. With no
// other object under the pointer there is nothing to select behind: the press is lent.
// A shown bounding box's handles and rotate zones are not passed to Select Behind: the press
// there is lent.
let live = vectorcraft_doc::hit::live_inputs();
let behind = painted_bounds(cx).is_some_and(|b| b.inflate(tol, tol).contains(p))
&& !shown_box(cx).is_some_and(|b| box_hit(cx, &b, p).is_some())
&& {
let stack = objects_at(cx.doc, p, cx.selection_hit_options(), cx.isolation);
stack.len() > 1 && holds_selection(cx, &stack).is_some()
}
&& !crate::direct::over_selected_part(cx, p);
if let Some(memo) = cx.preview_memo
&& let Ok(mut st) = memo.0.try_borrow_mut()
{
st.measurements += 1;
// Only the entry for the live inputs it was found with keeps the answer.
let m = PreviewMemo::current(&mut st, cx);
if m.live == live {
m.behind = Some((key, behind));
}
}
behind
}
/// The index in `stack` (objects under the pointer, topmost first) of the lowest object that is
/// selected or holds selected art, such as a group with a member picked by Direct Selection or
/// Group Selection.
fn holds_selection(cx: &ToolContext, stack: &[NodeId]) -> Option<usize> {
let holders = selection_holders(cx);
stack.iter().rposition(|id| holders.contains(id))
}
/// The selected objects and every object that holds one (their groups and layers), kept in the
/// session's [`PreviewMemo`] while the document and the selection stay as they are.
fn selection_holders(cx: &ToolContext) -> std::sync::Arc<std::collections::HashSet<NodeId>> {
remembered(
cx,
|m| &mut m.holders,
|| {
let set = cx.selection.objects.iter().flat_map(|&id| holder_chain(cx, id)).collect();
std::sync::Arc::new(set)
},
)
}
/// The selected object `id` and the objects holding it, outermost first, from the object a click
/// with the Selection tool selects for it ([`Hit::top_object`]): below its layers, the isolated
/// object and an envelope whose contents are edited.
fn holder_chain(cx: &ToolContext, id: NodeId) -> Vec<NodeId> {
let Some(a) = cx.doc.ancestry(id) else { return vec![id] };
let isolated = cx.isolation.and_then(|s| a.iter().position(|n| *n == s));
let contents =
a.iter().rposition(|n| cx.doc.node(*n).is_some_and(|n| matches!(n.kind, vectorcraft_doc::NodeKind::Envelope { editing: true, .. })));
// Below the isolated object or the envelope, the child holding `id` is the top object, a
// sublayer included; elsewhere layers and sublayers are skipped.
let chain: Vec<NodeId> = match isolated.max(contents) {
Some(i) => a.iter().skip(i + 1).copied().collect(),
None => a.iter().copied().skip_while(|n| cx.doc.node(*n).is_some_and(|n| n.is_layer())).collect(),
};
if chain.is_empty() { vec![id] } else { chain }
}
/// The object a click with the Selection tool selects for the selected object `id`
/// ([`holder_chain`]).
fn top_holder(cx: &ToolContext, id: NodeId) -> NodeId {
holder_chain(cx, id).first().copied().unwrap_or(id)
}
/// Select Behind: of the objects under `p` (topmost first), the one below the lowest one that is
/// selected or holds selected art, back to the topmost after the bottom one; the topmost when
/// none is.
fn object_behind(cx: &ToolContext, p: Point) -> Option<NodeId> {
let stack = objects_at(cx.doc, p, cx.selection_hit_options(), cx.isolation);
let next = stack.iter().rposition(|id| cx.selection.contains(*id)).map_or(0, |i| i + 1);
let next = holds_selection(cx, &stack).map_or(0, |i| i + 1);
stack.get(next).or(stack.first()).copied()
}
@@ -1624,6 +1851,14 @@ impl SelectionTool {
fn double_click(&mut self, cx: &ToolContext, p: Point, m: Mods) -> Vec<Action> {
self.state = State::Idle;
// Quick Cmd-clicks that select behind keep what the last one selected, before the widgets
// of that object answer, also when Cmd is let go before the release. Cmd+Shift on a guide
// still releases it. A double-click elsewhere, or after an edit or a selection change, is a
// double-click of its own. A press whose release has not come yet (both in one frame)
// still counts.
if self.pressed_behind.take().is_some_and(|(at, rev)| at.distance(p) <= cx.tol(1.0) && rev.is_none_or(|r| r == cx.revision)) {
return release_guide_at(cx, p, m).into_iter().collect();
}
// A threaded port: the thread breaks there. Any other port takes the double-click
// too, so it neither edits the type nor isolates.
if let Some((id, port)) = crate::text::port_at(cx, p) {
+35
View File
@@ -243,6 +243,9 @@ fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: O
let presenting = app.ui.screen_mode == 3;
let mut out = Body { context_at: artboards::show(app, ui, space, win, kind).map(|p| space.view.to_screen(p)), ..Body::default() };
grids(app, ui, space, win);
if live {
find_shown_tool(app, ui.ctx(), space);
}
marks::show(app, ui, space, win, kind);
if !presenting {
crate::panels::tabs::stop_guide(app, ui, space);
@@ -291,6 +294,38 @@ fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: O
out
}
/// The keys held now, as the engine's tools read them, with `space` set while Space is down.
pub(crate) fn held_mods(ctx: &egui::Context) -> vectorcraft_tools::Mods {
let (m, space) = ctx.input(|i| (i.modifiers, i.key_down(egui::Key::Space)));
mods(m, space)
}
/// The tool whose marks and widgets the canvas draws with the keys held now: while Cmd is held, the selection tool
/// a press at the pointer borrows ([`find_shown_tool`]), else the active tool.
pub(crate) fn shown_tool(app: &VectorcraftApp, ctx: &egui::Context) -> &'static str {
app.session.hover_tool_id(&held_mods(ctx))
}
/// Finds the tool whose marks and widgets the canvas draws this frame for the pointer where it is now
/// ([`vectorcraft_engine::Session::hover_tool_at`]), which [`shown_tool`] then answers. While the view moves, the art
/// under the pointer is not hit-tested again (#2452), and the last answer stays.
fn find_shown_tool(app: &mut VectorcraftApp, ctx: &egui::Context, space: &CanvasSpace) {
let wait = cursor::hover_wait(&mut app.canvas.view_moved, ViewKey::of(&space.view), craft::ui::runtime::frame::clock(ctx));
if wait.is_some() {
return;
}
let held = held_mods(ctx);
let named = app.session.shown_tool_id(&held);
let at = ctx.input(|i| i.pointer.hover_pos()).filter(|p| space.view.rect.contains(*p)).map(|p| space.view.to_doc(p));
let view = app.view_info();
app.session.hover_tool_at(at, &held, view);
// The status bar and the help bar are drawn before the canvas: when the tool they name changes with this
// frame's pointer, they are drawn again.
if app.session.shown_tool_id(&held) != named {
ctx.request_repaint();
}
}
/// The document grid, in the picture slot under the art when Grids In Back is on and over it
/// otherwise, and the pixel grid over the art.
fn grids(app: &VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, win: Win) {
+10 -9
View File
@@ -251,10 +251,9 @@ fn grid_path(key: u64, points: impl Iterator<Item = Point>, color: Color32) -> E
/// The anchors and handles of the selection. An object selected whole has every anchor selected, and so do the
/// paths inside a group, compound path or clip group selected whole; with Direct Selection's partial selection only
/// the chosen anchors are, and a selected segment hollows the others. `tool_points` is whether the tool draws its own
/// points (the Curvature tool while it draws), which leaves nothing here. Nothing too big to outline, and nothing
/// during Halftone Preview.
pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool_points: bool) -> Anchors {
let tool = app.session.tool_id();
/// points (the Curvature tool while it draws), which leaves nothing here. `tool` is the tool whose marks show
/// ([`super::shown_tool`]). Nothing too big to outline, and nothing during Halftone Preview.
pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool: &str, tool_points: bool) -> Anchors {
let curvature = tool == "curvature";
let prefs = &app.session.prefs;
let mut out = Anchors {
@@ -326,13 +325,13 @@ pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool_points: bool) ->
/// The outline of the object under the pointer at document point `at`, at view `zoom`, for Smart Guides › Object
/// Highlighting: the object a click of the selection tools would pick, unless it is selected or has too many points.
/// None while the view moves (`still` false), under Snap to Grid or Pixel Preview, with a tool that is busy or is not
/// a selection tool, and with the preference off.
pub(super) fn hover(app: &VectorcraftApp, st: &DocState, at: Point, zoom: f64, still: bool) -> Option<Hovered> {
/// a selection tool, and with the preference off. `tool` is the tool whose marks show ([`super::shown_tool`]): while
/// Cmd is held, the selection tool a press borrows.
pub(super) fn hover(app: &VectorcraftApp, st: &DocState, tool: &str, at: Point, zoom: f64, still: bool) -> Option<Hovered> {
let (view, prefs) = (&app.ui.view, &app.session.prefs);
if !still || !view.smart_guides || !prefs.object_highlighting || view.snap_to_grid || view.pixel_preview {
return None;
}
let tool = app.session.tool_id();
if app.session.tool_busy() || !matches!(tool, "selection" | "directSelection" | "groupSelection") {
return None;
}
@@ -467,10 +466,12 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
}
wait.is_none()
};
// While Cmd is held, the marks of the selection tool a press borrows.
let tool = super::shown_tool(app, ui.ctx());
let Some(st) = app.session.active() else { return };
let hovered = match (kind, app.hover_doc) {
(BodyKind::Pane, _) | (_, None) => None,
(_, Some(at)) => hover(app, st, at, space.view.zoom, still),
(_, Some(at)) => hover(app, st, tool, at, space.view.zoom, still),
};
if let Some(h) = hovered {
HoverOutline::new("Object highlight", Some(HoverShape::Path(h.path))).color(DataColor::new(h.color)).show_at(ui, rect);
@@ -482,7 +483,7 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
}
outline.show_at(ui, rect);
}
let marks = anchors(app, st, tool_points);
let marks = anchors(app, st, tool, tool_points);
if !marks.paths.is_empty() {
let mut paths = marks.paths;
// The marks only show the selection: the tools make the edits.
+7 -7
View File
@@ -47,7 +47,7 @@ fn revisions(seen: &Seen) -> Vec<u64> {
}
fn marks(app: &VectorcraftApp) -> Anchors {
anchors(app, app.session.active().unwrap(), false)
anchors(app, app.session.active().unwrap(), app.session.tool_id(), false)
}
fn all_selected(selection: &PathSelection) -> usize {
@@ -290,12 +290,12 @@ fn point_type_hover_shows_baseline_only_and_selection_shows_both_box_and_baselin
app.select_tool("selection");
let over = Point::new(220.0, 140.0);
let st = app.session.active().unwrap();
let hovered = hover(&app, st, over, 1.0, true).expect("the type under the pointer is outlined");
let hovered = hover(&app, st, app.session.tool_id(), over, 1.0, true).expect("the type under the pointer is outlined");
let line = hovered.path.bounding_box();
assert!((line.y0 - 150.0).abs() < 0.5 && line.height() < 0.5, "the baseline only, not the box: {line:?}");
app.run("select.set", json!({"ids": [id.0]})).unwrap();
let st = app.session.active().unwrap();
assert!(hover(&app, st, over, 1.0, true).is_none(), "a selected object has no hover outline");
assert!(hover(&app, st, app.session.tool_id(), over, 1.0, true).is_none(), "a selected object has no hover outline");
assert_eq!(outlines(&app, st)[0].paths.len(), 1, "the selection outlines the baseline; the box is the bounding box's");
}
@@ -308,7 +308,7 @@ fn hover_scene() -> VectorcraftApp {
}
fn hovered(app: &VectorcraftApp, still: bool) -> bool {
hover(app, app.session.active().unwrap(), Point::new(150.0, 150.0), 1.0, still).is_some()
hover(app, app.session.active().unwrap(), app.session.tool_id(), Point::new(150.0, 150.0), 1.0, still).is_some()
}
#[test]
@@ -340,7 +340,7 @@ fn a_group_of_too_many_paths_has_no_hover_outline_and_a_key_outline_of_its_bound
app.run("select.none", json!({})).unwrap();
app.select_tool("selection");
let st = app.session.active().unwrap();
assert!(hover(&app, st, Point::new(20.0, 20.0), 1.0, true).is_none(), "no hover outline for what is too big");
assert!(hover(&app, st, app.session.tool_id(), Point::new(20.0, 20.0), 1.0, true).is_none(), "no hover outline for what is too big");
// A key object stays while another selected object lies outside it.
let other = id_of(&app.run("shape.rectangle", json!({"x": 300, "y": 20, "width": 20, "height": 20})).unwrap());
app.run("select.set", json!({"ids": [huge.0, other.0]})).unwrap();
@@ -356,9 +356,9 @@ fn curvature_marks_existing_paths_as_circles_and_leaves_a_drafts_points_to_the_t
app.run("select.set", json!({"ids": [curve.0]})).unwrap();
app.select_tool("curvature");
let st = app.session.active().unwrap();
let existing = anchors(&app, st, false);
let existing = anchors(&app, st, app.session.tool_id(), false);
assert_eq!((existing.shown, existing.paths.len()), (AnchorsShown::Curvature, 1), "one circle per point of the existing path");
assert!(anchors(&app, st, true).paths.is_empty(), "while the tool draws its own points, none are drawn twice");
assert!(anchors(&app, st, app.session.tool_id(), true).paths.is_empty(), "while the tool draws its own points, none are drawn twice");
app.select_tool("directSelection");
assert_eq!(marks(&app).shown, AnchorsShown::All);
assert!(!marks(&app).paths.is_empty(), "other tools keep their anchors whatever `tool_points` says");
+22 -8
View File
@@ -531,24 +531,32 @@ pub(super) fn end_hidden(app: &mut VectorcraftApp, held: &mut Option<Held>, layo
}
}
/// Which widgets the app's tool and view show.
pub(super) fn shown(app: &VectorcraftApp) -> Show {
let tool = app.session.tool_id();
/// Which widgets `tool` and the app's view show. `tool` is the tool whose widgets the canvas shows
/// ([`super::shown_tool`]): while Cmd is held, the selection tool a press borrows.
pub(super) fn shown(app: &VectorcraftApp, tool: &str) -> Show {
let revolve_edit = super::revolve_editing(app);
let selecting = tool == "selection" && app.ui.view.edges && !revolve_edit;
Show { nine: true, selecting, shaper: matches!(tool, "shaper" | "selection") && !revolve_edit, trace: selecting && !app.outline_view() }
}
/// Shows the widgets over the document and runs the presses on them. Runs before the tool host, so a press on a part
/// never reaches the tool.
/// never reaches the tool. While Cmd lends the Selection tool, its widgets show and take a press as that tool's,
/// without Cmd, and a press on one keeps them until the release.
pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSpace, win: super::Win, kind: BodyKind) {
if kind != BodyKind::Live || app.ui.screen_mode == 3 {
return;
}
let (visible, info) = (shown(app), app.view_info());
let layout = app.session.with_tool_context(info, |cx| Layout::of(cx, &space.view, visible));
let id = super::canvas_id(win).with("selection_widget_drag");
let tool_id = id.with("tool");
let mut held: Option<Held> = ui.data(|d| d.get_temp::<Option<Held>>(id)).flatten();
let tool = match held {
Some(_) => ui.data(|d| d.get_temp::<&'static str>(tool_id)),
None => None,
}
.unwrap_or_else(|| super::shown_tool(app, ui.ctx()));
let lent = tool != app.session.tool_id();
let (visible, info) = (shown(app, tool), app.view_info());
let layout = app.session.with_tool_context(info, |cx| Layout::of(cx, &space.view, visible));
end_hidden(app, &mut held, &layout);
let out = SelectionWidgets::new(layout).show(ui);
for (widget, press) in out.presses {
@@ -563,7 +571,13 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
PressPhase::Cancel { .. } => Gesture::Cancel,
_ => continue,
};
advance(app, &mut held, widget, g, super::tool_adapter::tool_mods(press.mods, false));
let mut mods = super::tool_adapter::tool_mods(press.mods, false);
// The lent tool takes the press as a plain one, as the session lends it.
mods.cmd &= !lent;
advance(app, &mut held, widget, g, mods);
}
ui.data_mut(|d| d.insert_temp(id, held));
ui.data_mut(|d| {
d.insert_temp(id, held);
d.insert_temp(tool_id, tool);
});
}
@@ -73,7 +73,7 @@ fn check_tool_switch_cancels(app: &mut VectorcraftApp, widget: Widget, at: Pos2,
advance(app, &mut held, widget, Gesture::Move(v.to_doc(q)), Mods::default());
assert_ne!(*app.session.active().unwrap().doc, *before, "the drag previews");
app.select_tool("directSelection");
let visible = shown(app);
let visible = shown(app, app.session.tool_id());
let l = layout(app, visible);
end_hidden(app, &mut held, &l);
assert!(held.is_none(), "a tool switch cancels the drag");
@@ -354,3 +354,52 @@ fn app_with_radial() -> VectorcraftApp {
app.run("object.repeat.radial", json!({"instances": 6, "radius": 60})).unwrap();
app
}
/// The widgets only the Selection tool presses (a Shaper Group's mode widget, a mirror repeat's axis, a grid or radial
/// repeat's handles) hide while Cmd lends Direct Selection, and come back when the key is let go.
#[test]
fn selection_tool_widgets_hide_while_cmd_lends_direct_selection() {
let count = |app: &mut VectorcraftApp, held: egui::Modifiers, widget: Widget| {
let tool = app.session.hover_tool_id(&crate::canvas::mods(held, false));
let visible = shown(app, tool);
widgets(&layout(app, visible), widget)
};
// Each widget that does not show, hide or come back as it should.
let mut wrong = vec![];
let mut check = |app: &mut VectorcraftApp, widget: Widget| {
app.select_tool("selection");
let plain = count(app, egui::Modifiers::NONE, widget);
let cmd = count(app, egui::Modifiers::COMMAND, widget);
let back = count(app, egui::Modifiers::NONE, widget);
if plain == 0 || cmd != 0 || back != plain {
wrong.push(format!("{widget:?}: {plain} shown, {cmd} with Cmd held, {back} after"));
}
};
let mut shaper = app();
for x in [0, 50] {
shaper.run("shape.rectangle", json!({"x": x, "y": 0, "width": 100, "height": 100})).unwrap();
}
shaper.run("shaper.scribble", json!({"points": [[25, 20], [75, 35], [30, 50], [125, 65]]})).unwrap();
check(&mut shaper, Widget::Shaper);
check(&mut mirror_app().0, Widget::Mirror);
let mut grid = app();
grid.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 40, "height": 40})).unwrap();
grid.run("object.repeat.grid", json!({"hSpacing": 10, "vSpacing": 10})).unwrap();
check(&mut grid, Widget::Grid);
check(&mut app_with_radial(), Widget::Radial);
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
}
/// With Direct Selection, Cmd held lends the Selection tool, and its widgets show.
#[test]
fn cmd_held_with_direct_selection_shows_the_selection_tools_widgets() {
let (mut app, _) = mirror_app();
app.select_tool("directSelection");
let tool = |app: &VectorcraftApp, held| app.session.hover_tool_id(&crate::canvas::mods(held, false));
let own = shown(&app, tool(&app, egui::Modifiers::NONE));
assert_eq!(widgets(&layout(&mut app, own), Widget::Mirror), 0, "Direct Selection's own");
let lent = tool(&app, egui::Modifiers::COMMAND);
assert_eq!(lent, "selection");
let visible = shown(&app, lent);
assert!(widgets(&layout(&mut app, visible), Widget::Mirror) > 0, "the Selection tool's, lent by Cmd");
}
+30 -1
View File
@@ -138,6 +138,34 @@ fn a_release_ends_the_image_trace_hold_without_the_panel() {
frame(&mut app, &ctx, vec![press(false)]);
}
/// The canvas decides which tool's marks and widgets to show for the pointer where it is in the same frame: over the
/// selected blend a Cmd press selects behind, so the Selection tool's stay; moved away in the next frame, where Cmd
/// lends Direct Selection, they are Direct Selection's in that frame.
#[test]
fn the_shown_tool_follows_the_pointer_in_the_frame_it_moves() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
let id = |v: serde_json::Value| v["id"].as_u64().unwrap();
// Behind the blend, an object to select behind.
app.session.execute("shape.rectangle", &json!({"x": 20, "y": 120, "width": 360, "height": 160})).unwrap();
let a = id(app.session.execute("shape.rectangle", &json!({"x": 60, "y": 160, "width": 80, "height": 80})).unwrap());
let b = id(app.session.execute("shape.rectangle", &json!({"x": 260, "y": 160, "width": 80, "height": 80})).unwrap());
app.session.execute("select.set", &json!({"ids": [a, b]})).unwrap();
let blend = id(app.session.execute("object.blend.make", &json!({})).unwrap());
app.select_tool("selection");
app.session.execute("select.set", &json!({"ids": [blend]})).unwrap();
let ctx = crate::testing::ui_context();
frame(&mut app, &ctx, vec![]);
let xf = app.canvas_view().unwrap();
let cmd_frame = |app: &mut VectorcraftApp, at: Point| {
frame(app, &ctx, vec![egui::Event::ModifiersChanged(egui::Modifiers::COMMAND), egui::Event::PointerMoved(xf.to_screen(at))]);
app.session.hover_tool_id(&Mods { cmd: true, ..Default::default() })
};
// Inside the first key object, away from its anchors and the spine.
assert_eq!(cmd_frame(&mut app, Point::new(80.0, 175.0)), "selection", "over the selected blend, the press selects behind");
assert_eq!(cmd_frame(&mut app, Point::new(200.0, 380.0)), "directSelection", "away from it, in the same frame");
}
/// A click with the Selection tool inside an artboard makes it the active one, and Paste in
/// Place then pastes onto it, where the objects were on their own artboard (#693).
#[test]
@@ -520,7 +548,8 @@ fn halftone_preview_hides_dot_outlines_and_keeps_selection_bounds() {
app.ui_ctx = Some(ctx.clone());
// Whether the selection shows its objects' outlines; the box around it shows throughout.
let outlined = |app: &mut VectorcraftApp| {
assert!(super::widgets::bounding_box(app, egui::Modifiers::NONE).is_some(), "the selection box is still drawn");
let tool = app.session.tool_id();
assert!(super::widgets::bounding_box(app, tool).is_some(), "the selection box is still drawn");
let app = &*app;
let st = app.session.active().unwrap();
!super::selection::outlines(app, st).is_empty()
+7 -3
View File
@@ -373,8 +373,12 @@ impl CanvasTool for SessionTool<'_> {
let switched = follow == PointerKind::DoubleClick && before != "type" && self.app().session.tool_id() == "type";
if switched {
self.app().session.set_tool_option("prevTool", &json!(before));
self.send(PointerKind::Down, pointer, cx);
self.send(PointerKind::Up, pointer, cx);
for kind in [PointerKind::Down, PointerKind::Up] {
// Without Cmd, so the Type tool takes the click instead of lending a selection tool.
let mut ev = pointer_event(kind, pointer, cx);
ev.mods.cmd = false;
dispatch(&mut self.app(), &ev, self.view);
}
}
}
@@ -700,7 +704,7 @@ pub fn dispatch(app: &mut VectorcraftApp, ev: &PointerEvent, view: ViewInfo) {
return;
}
// A press lent to a selection tool (Cmd/Ctrl held) does not use the tool of a held key.
if ev.kind == PointerKind::Down && app.session.lent_tool_id(&ev.mods).is_none() {
if ev.kind == PointerKind::Down && !app.session.press_lends_tool(ev, view) {
crate::shortcuts::note_tool_use(app);
}
let r = app.session.pointer(ev, view);
+28 -26
View File
@@ -40,34 +40,34 @@ fn doc_point(p: vectorcraft_geom::Point) -> Point {
Point::new(p.x, p.y)
}
/// Is the active tool a shape tool that is not drawing a shape? While it draws it shows none of its widgets;
/// adjusting a widget, it shows them.
fn shape_tool_idle(app: &VectorcraftApp) -> bool {
vectorcraft_tools::shape::shows_shape_widgets(app.session.tool_id()) && !(app.session.tool_busy() && !app.session.tool_transforming())
/// Is the active tool a shape tool that is not drawing a shape, and `tool`, the tool whose widgets the canvas shows,
/// is that tool (Cmd lends no other)? While it draws it shows none of its widgets; adjusting a widget, it shows them.
fn shape_tool_idle(app: &VectorcraftApp, tool: &str) -> bool {
tool == app.session.tool_id()
&& vectorcraft_tools::shape::shows_shape_widgets(tool)
&& !(app.session.tool_busy() && !app.session.tool_transforming())
}
/// The bounding box to draw, if any: the Selection tool's (rotated with the objects after a rotation), also
/// shown by the shape tools that keep a shape just drawn ready to adjust, and by Cmd held over another tool,
/// which lends the Selection tool to a press. It hides while a drag moves, rotates or resizes the selection, so
/// shown by the shape tools that keep a shape just drawn ready to adjust, and by Cmd held over another tool
/// where it lends the Selection tool to a press. It hides while a drag moves, rotates or resizes the selection, so
/// only the art is seen going with the pointer; a handle resize keeps it at the changing bounds. With General ›
/// Show Bounding Box While Moving and Drawing on, a move draws it where the drag has moved the selection and a
/// shape tool draws it around the shape being drawn. With Real-time Drawing off the document stays at the
/// drag's snapshot, so a resize or a shape being drawn measures the box from the pending preview; a shape being
/// drawn shows no box until a preview has made it. `held` is the modifiers held now; a second pass of a frame
/// reads the same held state, which is not an event.
/// drawn shows no box until a preview has made it. `tool` is the tool whose marks the canvas shows
/// ([`super::shown_tool`]): while Cmd is held, the selection tool a press borrows, so the box shows only when that
/// is the Selection tool, whose handles take the press.
// PLAN: the sheet's `(app, st)` cannot work: `selection_box` and `deferred_transform_box` need `&mut app`, so the
// active document is read inside.
pub(super) fn bounding_box(app: &mut VectorcraftApp, held: egui::Modifiers) -> Option<ShownBox> {
pub(super) fn bounding_box(app: &mut VectorcraftApp, tool: &str) -> Option<ShownBox> {
let resizing = app.session.tool_resizing();
let move_box = app.session.move_drag_box();
let drawing_boxed = app.session.draws_new_shape_box();
let follows = resizing || move_box.is_some() || drawing_boxed;
let selection_tool = app.session.tool_id() == "selection";
let shape_tool = vectorcraft_tools::shape::shows_shape_widgets(app.session.tool_id());
// PLAN: assumed `super::mods(egui::Modifiers, bool) -> Mods` stays at `canvas` (sheet w20).
let held = super::mods(held, false);
let lends_selection = !app.session.tool_busy() && app.session.lent_tool_id(&held) == Some("selection");
let show_box = (selection_tool || lends_selection || (shape_tool && (!app.session.tool_busy() || follows)))
let own = tool == app.session.tool_id();
let shape_tool = own && vectorcraft_tools::shape::shows_shape_widgets(tool);
let show_box = (tool == "selection" || (shape_tool && (!app.session.tool_busy() || follows)))
&& (follows || !app.session.tool_transforming())
&& app.ui.view.bounding_box;
if !show_box {
@@ -114,13 +114,13 @@ fn corner_target(doc: &Document, id: NodeId, indices: &[usize]) -> Option<Corner
/// The Live Corners widgets on show, one group per layer colour so each draws in its object's colour: Selection
/// and the shape tools on a live rectangle or polygon while Show Shape Widgets is on, Direct Selection on any
/// path. Only the corners the tool hit-tests are listed, those within the Hide Corner Widget angle.
/// path. Only the corners the tool hit-tests are listed, those within the Hide Corner Widget angle. `tool` is the tool
/// whose widgets the canvas shows ([`super::shown_tool`]).
// PLAN: the decision's `(.., f64)` is dropped: the corners listed are already those within the angle, so no
// angle is left to hand on.
pub(super) fn corners(app: &VectorcraftApp, zoom: f64) -> Option<Vec<(DataColor, Vec<CornerTarget>)>> {
let tool = app.session.tool_id();
pub(super) fn corners(app: &VectorcraftApp, tool: &str, zoom: f64) -> Option<Vec<(DataColor, Vec<CornerTarget>)>> {
let direct = tool == "directSelection";
if !(matches!(tool, "selection" | "directSelection") || shape_tool_idle(app)) {
if !(matches!(tool, "selection" | "directSelection") || shape_tool_idle(app, tool)) {
return None;
}
let st = app.session.active()?;
@@ -222,11 +222,11 @@ impl ShapeWidgets {
/// The widgets of the active document at `zoom` (screen points per document unit) under a view turned by
/// `rotation`. `edges` is View › Show Edges: the type, side and pie widgets go with it, the blend and Objects
/// on Path widgets are controls and stay. `shown` is the bounding box on show, which the type and side
/// widgets sit beside; a shape being drawn has neither.
fn of(app: &VectorcraftApp, edges: bool, shown: Option<&ShownBox>, zoom: f64, rotation: f64) -> Self {
/// widgets sit beside; a shape being drawn has neither. `tool` is the tool whose widgets the canvas shows
/// ([`super::shown_tool`]): while Cmd is held, the selection tool a press borrows.
fn of(app: &VectorcraftApp, tool: &str, edges: bool, shown: Option<&ShownBox>, zoom: f64, rotation: f64) -> Self {
let mut marks = vec![];
let Some(st) = app.session.active() else { return Self::new(marks) };
let tool = app.session.tool_id();
let layer = |id| data_color(st.doc.layer_color(id));
let shape_widgets = app.ui.view.shape_widgets;
if edges {
@@ -240,7 +240,7 @@ impl ShapeWidgets {
}
}
// Pie widgets stay while one is dragged, each joined to the outline's point at its angle.
if app.ui.view.bounding_box && shape_widgets && (tool == "selection" || shape_tool_idle(app)) {
if app.ui.view.bounding_box && shape_widgets && (tool == "selection" || shape_tool_idle(app, tool)) {
for w in pie::PieWidget::of(&st.doc, &st.selection, zoom) {
marks.push(Mark::new(Form::Disc, Filling::Hollow, w.at, pie::RADIUS_PX, layer(w.id)).joined(w.on));
}
@@ -353,16 +353,18 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &craft::u
// PLAN: assumed the body's rect is the canvas rect the controls are shown at.
let rect = ui.max_rect();
let edges = app.ui.view.edges;
let shown = if edges { bounding_box(app, ui.input(|i| i.modifiers)) } else { None };
// While Cmd is held, the widgets of the selection tool a press borrows.
let tool = super::shown_tool(app, ui.ctx());
let shown = if edges { bounding_box(app, tool) } else { None };
if edges {
for (at, (color, targets)) in corners(app, space.view.zoom).into_iter().flatten().enumerate() {
for (at, (color, targets)) in corners(app, tool, space.view.zoom).into_iter().flatten().enumerate() {
CornerWidgets::new("Live Corners", Bind::given(targets)).id_salt(at).reach(TransformReach::Shown).color(color).show_at(ui, rect);
}
if let Some(b) = &shown {
show_box(ui, rect, b);
}
}
let widgets = ShapeWidgets::of(app, edges, shown.as_ref(), space.view.zoom, space.view.rotation);
let widgets = ShapeWidgets::of(app, tool, edges, shown.as_ref(), space.view.zoom, space.view.rotation);
if !widgets.marks.is_empty() {
widgets.show_at(ui, rect);
}
+81 -30
View File
@@ -37,10 +37,28 @@ fn layer(app: &VectorcraftApp, id: u64) -> DataColor {
data_color(app.session.active().unwrap().doc.layer_color(vectorcraft_doc::NodeId(id)))
}
fn marks(app: &mut VectorcraftApp) -> Vec<Mark> {
let shown = bounding_box(app, NONE);
/// The tool whose widgets show with `held` and the pointer off the canvas: while Cmd is held, the selection tool it
/// lends.
fn shown(app: &VectorcraftApp, held: egui::Modifiers) -> &'static str {
app.session.hover_tool_id(&super::super::mods(held, false))
}
/// The bounding box on show with `held`.
fn boxed(app: &mut VectorcraftApp, held: egui::Modifiers) -> Option<ShownBox> {
let tool = shown(app, held);
bounding_box(app, tool)
}
/// The shape widgets on show with `held`.
fn marks_with(app: &mut VectorcraftApp, held: egui::Modifiers) -> Vec<Mark> {
let tool = shown(app, held);
let shown = bounding_box(app, tool);
let zoom = app.view_info().zoom;
ShapeWidgets::of(app, true, shown.as_ref(), zoom, 0.0).marks
ShapeWidgets::of(app, tool, true, shown.as_ref(), zoom, 0.0).marks
}
fn marks(app: &mut VectorcraftApp) -> Vec<Mark> {
marks_with(app, NONE)
}
fn count(marks: &[Mark], form: Form, radius: f32) -> usize {
@@ -49,7 +67,7 @@ fn count(marks: &[Mark], form: Form, radius: f32) -> usize {
fn corner_count(app: &VectorcraftApp) -> usize {
let zoom = app.view_info().zoom;
corners(app, zoom).map_or(0, |groups| groups.iter().flat_map(|(_, targets)| targets).map(|t| t.corners.len()).sum())
corners(app, app.session.tool_id(), zoom).map_or(0, |groups| groups.iter().flat_map(|(_, targets)| targets).map(|t| t.corners.len()).sum())
}
#[test]
@@ -59,9 +77,9 @@ fn real_time_drawing_off_moves_the_bounding_box_with_a_move_drag() {
let mut app = new_app(&[("realTimeDrawing", json!(real_time)), ("boundingBoxWhileMovingAndDrawing", json!(while_moving))]);
make(&mut app, "shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 60}));
app.select_tool("selection");
assert!(bounding_box(&mut app, NONE).is_some(), "{what}: at rest");
assert!(boxed(&mut app, NONE).is_some(), "{what}: at rest");
drag(&mut app, (150.0, 130.0), (250.0, 230.0));
let during = bounding_box(&mut app, NONE);
let during = boxed(&mut app, NONE);
if real_time && !while_moving {
assert!(during.is_none(), "{what}: hidden while the art moves");
} else {
@@ -69,7 +87,7 @@ fn real_time_drawing_off_moves_the_bounding_box_with_a_move_drag() {
assert_eq!((rect.x0, rect.y0), (200.0, 200.0), "{what}: where the drag carries the selection");
}
pointer(&mut app, PointerKind::Up, (250.0, 230.0));
assert_eq!(bounding_box(&mut app, NONE).unwrap().obox.rect.x0, 200.0, "{what}: at rest after the release");
assert_eq!(boxed(&mut app, NONE).unwrap().obox.rect.x0, 200.0, "{what}: at rest after the release");
}
}
@@ -80,7 +98,7 @@ fn corner_widgets_hide_above_the_preference_angle() {
app.select_tool("selection");
assert_eq!(corner_count(&app), 4);
app.session.execute("prefs.set", &json!({"key": "hideCornerWidgetAbove", "value": 80})).unwrap();
assert!(corners(&app, app.view_info().zoom).is_none());
assert!(corners(&app, app.session.tool_id(), app.view_info().zoom).is_none());
}
#[test]
@@ -89,12 +107,12 @@ fn a_resize_drag_keeps_the_bounding_box_at_the_new_bounds() {
let mut app = new_app(&[("realTimeDrawing", json!(real_time))]);
make(&mut app, "shape.ellipse", json!({"x": 100, "y": 100, "width": 100, "height": 60}));
app.select_tool("selection");
let before = bounding_box(&mut app, NONE).unwrap();
let before = boxed(&mut app, NONE).unwrap();
drag(&mut app, (200.0, 160.0), (263.0, 211.0));
assert!(app.session.tool_resizing(), "real time {real_time}: the handle was hit");
let during = bounding_box(&mut app, NONE).unwrap();
let during = boxed(&mut app, NONE).unwrap();
pointer(&mut app, PointerKind::Up, (263.0, 211.0));
let after = bounding_box(&mut app, NONE).unwrap();
let after = boxed(&mut app, NONE).unwrap();
assert_ne!(after.obox.rect, before.obox.rect, "real time {real_time}: the drag resized the ellipse");
assert_eq!(during.obox.rect, after.obox.rect, "real time {real_time}: the box followed the drag");
}
@@ -106,13 +124,13 @@ fn a_move_drag_keeps_the_bounding_box_where_the_drag_carries_the_selection() {
make(&mut app, "shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100}));
app.select_tool("selection");
drag(&mut app, (150.0, 150.0), (170.0, 160.0));
let rect = bounding_box(&mut app, NONE).unwrap().obox.rect;
let rect = boxed(&mut app, NONE).unwrap().obox.rect;
assert_eq!((rect.x0, rect.y0), (120.0, 110.0));
app.ui.view.bounding_box = false;
assert!(bounding_box(&mut app, NONE).is_none(), "View › Hide Bounding Box");
assert!(boxed(&mut app, NONE).is_none(), "View › Hide Bounding Box");
app.ui.view.bounding_box = true;
app.session.execute("prefs.set", &json!({"key": "boundingBoxWhileMovingAndDrawing", "value": false})).unwrap();
assert!(bounding_box(&mut app, NONE).is_none(), "off: hidden while the selection moves");
assert!(boxed(&mut app, NONE).is_none(), "off: hidden while the selection moves");
}
#[test]
@@ -124,12 +142,12 @@ fn a_shape_being_drawn_shows_its_bounding_box() {
app.select_tool(tool);
drag(&mut app, (150.0, 120.0), (180.0, 140.0));
assert!(app.session.draws_new_shape_box(), "{what}");
let first = bounding_box(&mut app, NONE).unwrap_or_else(|| panic!("{what}: no box")).obox;
let first = boxed(&mut app, NONE).unwrap_or_else(|| panic!("{what}: no box")).obox;
pointer(&mut app, PointerKind::Drag, (210.0, 170.0));
let during = bounding_box(&mut app, NONE).unwrap().obox;
let during = boxed(&mut app, NONE).unwrap().obox;
assert_ne!(first.rect, during.rect, "{what}: the box follows the drag");
app.session.execute("prefs.set", &json!({"key": "boundingBoxWhileMovingAndDrawing", "value": false})).unwrap();
assert!(bounding_box(&mut app, NONE).is_none(), "{what}: off, no box while drawing");
assert!(boxed(&mut app, NONE).is_none(), "{what}: off, no box while drawing");
}
}
}
@@ -141,12 +159,12 @@ fn a_failed_preview_of_a_shape_being_drawn_shows_no_bounding_box() {
make(&mut app, "shape.rectangle", json!({"x": 20, "y": 20, "width": 30, "height": 30}));
app.select_tool("rectangle");
drag(&mut app, (150.0, 120.0), (180.0, 140.0));
assert!(bounding_box(&mut app, NONE).is_some(), "real time {real_time}: the box of the shape being drawn");
assert!(boxed(&mut app, NONE).is_some(), "real time {real_time}: the box of the shape being drawn");
assert!(app.session.preview("shape.rectangle", &json!({"x": "left"})).is_err());
assert!(app.session.draws_new_shape_box() && app.session.interaction_unapplied());
assert!(bounding_box(&mut app, NONE).is_none(), "real time {real_time}: not the old selection's box");
assert!(boxed(&mut app, NONE).is_none(), "real time {real_time}: not the old selection's box");
pointer(&mut app, PointerKind::Drag, (210.0, 170.0));
assert!(bounding_box(&mut app, NONE).is_some(), "real time {real_time}: the next preview shows it again");
assert!(boxed(&mut app, NONE).is_some(), "real time {real_time}: the next preview shows it again");
}
}
@@ -161,7 +179,7 @@ fn a_shape_being_drawn_has_its_box_in_its_own_layers_color() {
assert_ne!(old_color, new_color);
app.select_tool("rectangle");
drag(&mut app, (150.0, 120.0), (180.0, 140.0));
assert_eq!(bounding_box(&mut app, NONE).unwrap().color, new_color, "real time {real_time}");
assert_eq!(boxed(&mut app, NONE).unwrap().color, new_color, "real time {real_time}");
}
}
@@ -174,7 +192,7 @@ fn a_shape_being_drawn_has_no_type_widget() {
assert_eq!(count(&marks(&mut app), Form::Disc, typewidget::RADIUS_PX), 1, "the selected type's widget");
app.select_tool("rectangle");
drag(&mut app, (150.0, 120.0), (210.0, 170.0));
assert!(bounding_box(&mut app, NONE).is_some(), "the box of the shape being drawn");
assert!(boxed(&mut app, NONE).is_some(), "the box of the shape being drawn");
assert_eq!(count(&marks(&mut app), Form::Disc, typewidget::RADIUS_PX), 0, "no type widget beside it");
}
@@ -189,7 +207,7 @@ fn freehand_and_pen_drawing_show_no_bounding_box() {
pointer(&mut app, PointerKind::Drag, at);
}
assert!(!app.session.draws_new_shape_box(), "{tool}");
assert!(bounding_box(&mut app, NONE).is_none(), "{tool}: no box while it draws");
assert!(boxed(&mut app, NONE).is_none(), "{tool}: no box while it draws");
pointer(&mut app, PointerKind::Up, (210.0, 170.0));
}
}
@@ -216,10 +234,10 @@ fn a_move_rotate_or_corner_radius_drag_hides_the_bounding_box() {
((corner.x, corner.y), (corner.x + 10.0, corner.y + 10.0))
}
};
assert!(bounding_box(&mut app, NONE).is_some(), "{what}: at rest");
assert!(boxed(&mut app, NONE).is_some(), "{what}: at rest");
drag(&mut app, from, to);
assert!(app.session.tool_transforming(), "{what}");
assert!(bounding_box(&mut app, NONE).is_none(), "{what}: hidden during the drag");
assert!(boxed(&mut app, NONE).is_none(), "{what}: hidden during the drag");
pointer(&mut app, PointerKind::Up, to);
}
}
@@ -229,9 +247,9 @@ fn direct_selection_shows_the_bounding_box_while_cmd_is_held() {
let mut app = new_app(&[]);
make(&mut app, "shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 50}));
app.select_tool("directSelection");
assert!(bounding_box(&mut app, NONE).is_none(), "Direct Selection alone shows no box");
assert!(bounding_box(&mut app, egui::Modifiers::COMMAND).is_some(), "Cmd held shows the Selection tool's box");
assert!(bounding_box(&mut app, NONE).is_none(), "gone once Cmd is released");
assert!(boxed(&mut app, NONE).is_none(), "Direct Selection alone shows no box");
assert!(boxed(&mut app, egui::Modifiers::COMMAND).is_some(), "Cmd held shows the Selection tool's box");
assert!(boxed(&mut app, NONE).is_none(), "gone once Cmd is released");
assert!(app.ui.view.bounding_box, "View › Show Bounding Box is unchanged");
}
@@ -279,6 +297,39 @@ fn a_selected_ellipse_shows_its_pie_widgets() {
assert_eq!(count(&marks(&mut app), Form::Disc, pie::RADIUS_PX), 0, "no bounding box, no widgets");
}
/// With a shape tool, Cmd held lends the selection tool chosen last; when that is Direct Selection, which does not
/// press them, a selected live ellipse's pie widgets hide while the key is down.
#[test]
fn pie_widgets_hide_while_cmd_lends_direct_selection() {
let mut app = new_app(&[]);
make(&mut app, "shape.ellipse", json!({"x": 100, "y": 100, "width": 200, "height": 100}));
app.session.execute("object.setLiveShape", &json!({"pieStart": 0, "pieEnd": 90})).unwrap();
app.select_tool("directSelection");
app.select_tool("ellipse");
let pies = |app: &mut VectorcraftApp, held| count(&marks_with(app, held), Form::Disc, pie::RADIUS_PX);
assert_eq!(pies(&mut app, NONE), 2, "the Ellipse tool shows them");
assert_eq!(pies(&mut app, egui::Modifiers::COMMAND), 0, "hidden while Cmd lends Direct Selection");
assert_eq!(pies(&mut app, NONE), 2, "back when the key is let go");
}
/// With the Selection tool, Cmd held lends Direct Selection away from the selection, and a selected blend's widgets,
/// which only the Selection and Blend tools press, hide while the key is down.
#[test]
fn blend_widgets_hide_while_cmd_lends_direct_selection() {
let mut app = new_app(&[]);
let a = make(&mut app, "shape.rectangle", json!({"x": 90, "y": 190, "width": 20, "height": 20}));
let b = make(&mut app, "shape.rectangle", json!({"x": 290, "y": 190, "width": 20, "height": 20}));
app.session.execute("select.set", &json!({"ids": [a, b]})).unwrap();
let blend = make(&mut app, "object.blend.make", json!({}));
app.select_tool("selection");
app.session.execute("select.set", &json!({"ids": [blend]})).unwrap();
let widgets = |app: &mut VectorcraftApp, held| count(&marks_with(app, held), Form::Disc, blendwidget::RADIUS_PX);
let plain = widgets(&mut app, NONE);
assert!(plain >= 1, "the Appearance widget: {plain}");
assert_eq!(widgets(&mut app, egui::Modifiers::COMMAND), 0, "hidden while Cmd lends Direct Selection");
assert_eq!(widgets(&mut app, NONE), plain, "back when the key is let go");
}
#[test]
fn a_selected_polygon_shows_its_side_widget() {
let mut app = new_app(&[]);
@@ -310,7 +361,7 @@ fn hidden_shape_widgets_leave_the_bounding_box() {
let drawn = |app: &mut VectorcraftApp, id: u64| {
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
let m = marks(app);
(corner_count(app), count(&m, Form::Diamond, sidewidget::RADIUS_PX), count(&m, Form::Disc, pie::RADIUS_PX), bounding_box(app, NONE).is_some())
(corner_count(app), count(&m, Form::Diamond, sidewidget::RADIUS_PX), count(&m, Form::Disc, pie::RADIUS_PX), boxed(app, NONE).is_some())
};
for tool in ["selection", "polygon", "rectangle"] {
app.select_tool(tool);
@@ -363,7 +414,7 @@ fn a_selected_objects_on_path_group_shows_its_rotate_all_widget() {
app.run("select.set", json!({"ids": [group]})).unwrap();
let zoom = app.view_info().zoom;
app.select_tool("selection");
assert_eq!(count(&ShapeWidgets::of(&app, false, None, zoom, 0.0).marks, Form::Disc, r), 1);
assert_eq!(count(&ShapeWidgets::of(&app, "selection", false, None, zoom, 0.0).marks, Form::Disc, r), 1);
}
#[test]
+11 -1
View File
@@ -40,6 +40,14 @@ fn hint_for(tool: &str) -> Option<&'static [(&'static str, bool)]> {
("Shift+Click", true),
(" to add", false),
],
"groupSelection" => &[
("Click", true),
(" an object in a group to select it | ", false),
("Click again", true),
(" to add the group it is in | ", false),
("Shift+Click", true),
(" to add", false),
],
"pen" => &[
("Click", true),
(" to add a corner point | ", false),
@@ -254,7 +262,9 @@ pub fn hint_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
let segments: Vec<(Cow<'static, str>, bool)> = match crate::dialogs::three_d::hint(app) {
Some(hint) => vec![(Cow::Borrowed(hint), false)],
None => {
let tool = app.session.tool_id();
// While Cmd is held, the hints of the selection tool it lends.
let held = crate::canvas::held_mods(ui.ctx());
let tool = app.session.shown_tool_id(&held);
let hint = if tool == "zoom" && crate::canvas::animated_zoom(&app.session.prefs) { ANIMATED_ZOOM_HINT } else { tool };
hint_segments(app, hint)
}
+6 -4
View File
@@ -15,7 +15,8 @@ use craft::ui::text::ZoomField;
/// Shows the status bar: zoom, rotation, artboard navigator, the info field with its Show menu, the readouts, Stop,
/// the background-work progress and last the message, so a narrow bar elides the message before anything else.
pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
let (info, next) = info_text(app);
let held = crate::canvas::held_mods(ui.ctx());
let (info, next) = info_text(app, &held);
if let Some(secs) = next {
ui.ctx().request_repaint_after(std::time::Duration::from_secs(secs));
}
@@ -228,12 +229,13 @@ pub fn set_status_bar_show(app: &mut VectorcraftApp, p: &serde_json::Value) -> R
}
/// The info field's text for the choice in the Show menu, and for Date and Time the seconds until
/// the minute it shows ends (when the bar draws again).
pub(super) fn info_text(app: &VectorcraftApp) -> (String, Option<u64>) {
/// the minute it shows ends (when the bar draws again). Current Tool names the selection tool Cmd
/// lends while it is held (`held`).
pub(super) fn info_text(app: &VectorcraftApp, held: &vectorcraft_tools::Mods) -> (String, Option<u64>) {
let st = app.session.active();
match app.ui.status_bar_show {
StatusBarShow::CurrentTool => {
let tool = vectorcraft_tools::tool_info(app.session.tool_id())
let tool = vectorcraft_tools::tool_info(app.session.shown_tool_id(held))
.map(|t| {
// The catalog keys carry the full label ("Selection Tool"); only English drops the suffix.
let shown = tl!(t.label);
+13 -1
View File
@@ -528,6 +528,18 @@ fn combined_open_and_link_status_lists_notes_on_hover_and_for_accessibility() {
assert!(!described.as_deref().is_some_and(|d| d.contains("• ")) && shown.is_empty(), "a later message lists nothing: {described:?} {shown:?}");
}
/// While Cmd/Ctrl is held, Current Tool names the selection tool a press would borrow: Direct
/// Selection with the Selection tool chosen, and the Selection tool again once the key is let go.
#[test]
fn current_tool_names_the_selection_tool_cmd_lends() {
let bar = status_readout_app();
let app = bar.app();
let cmd = vectorcraft_tools::Mods { cmd: true, ..Default::default() };
assert_eq!(app.session.tool_id(), "selection");
assert_eq!(super::status_bar::info_text(&app, &cmd).0, "Direct Selection");
assert_eq!(super::status_bar::info_text(&app, &Default::default()).0, "Selection");
}
/// The status bar's info field shows the readout `view.statusBarShow` chooses: the navigator's
/// artboard name, the tool in use, the date and time, the undo and redo counts, or the document's
/// color profile.
@@ -564,7 +576,7 @@ fn the_status_bar_info_field_shows_the_chosen_readout() {
// The labels take the UI language's colon (#7991).
let fr = crate::i18n::Lang::from_code("fr").unwrap();
crate::i18n::set_current(fr);
let (french, _) = super::status_bar::info_text(&bar.app());
let (french, _) = super::status_bar::info_text(&bar.app(), &Default::default());
crate::i18n::set_current(crate::i18n::Lang::EN);
assert_eq!(french, format!("{}\u{a0}: {before} {}\u{a0}: 1", crate::i18n::tr(fr, "Undos"), crate::i18n::tr(fr, "Redos")));
+1 -1
View File
@@ -96,7 +96,7 @@ the two can still win that race.
| `ui.menu.list` / `ui.menu.invoke` | `{command, params}` | the full menu tree / invoke an item |
| `ui.contextMenu.list` | | the canvas context menu for the current selection, flattened like `ui.menu.list` (`path` holds its submenus). `ui.click {x, y, button: "right"}` on the canvas opens it, after selecting the object there unless it is already selected. With the Artboard tool it lists the artboard entries (see `docs/mcp.md`), after selecting the artboard there unless it is already selected. While a menu opened over locked objects is open, it has an `Unlock` submenu with one item for each locked object under the pointer, topmost first and at most 20, labeled with the object's name, which runs `layer.setProps {ids: [id], locked: false}`. A locked group gets one item, and the locked objects inside it get none. Hidden objects, objects on hidden, locked or template layers, and in isolation mode objects outside the isolated group get no item |
| `ui.tool.select` / `ui.tool.list` | `{tool}` | |
| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick\|tripleclick, x, y, space?: "doc"\|"screen", mods?}]}` | drive the active tool exactly like the mouse (`doubleclick` follows the second click's `up`, and `tripleclick` the third's): `mods.cmd` held at a press with any tool but a selection tool drags with the selection tool chosen last (Direct Selection with the Pen until one is), and the release gives the tool back as it was; the reply lists `selection`, `key` (the key object, null without one) and `tool`. With the Shape Builder or the Live Paint Bucket and a selection of more than 128 segments, the app finds the regions off the UI thread, so a `move` replies before the region under the pointer is highlighted, and the highlight shows in the first frame after the regions are found. With the Shape Builder and such a selection, the app also merges off the UI thread: the reply to the events that end a click or drag comes once the merge is applied. A click or drag made before the regions are found does not wait for them; the app records it and makes it once they are found. Until then the canvas keeps drawing, with the touched regions highlighted and the busy pointer. A click or drag sent meanwhile, with `mods.cmd` too, and the Shape Builder's arrow keys are made after the merge in the order sent, and the reply to such a request comes once its events are made and any merge they start is applied; a request of `move` events alone is answered at once. A command that can edit, select, save or redraw the documents (an edit, an undo, a selection, a save or an export, a tool option, another tool, another document, closing, a dialog's preview, a menu item, a command of the app's own such as `ui.recolorDialog`, the proof and separations views, a preference, added fonts) waits for the merge and the input sent before it, and runs after them; queries that only read, such as `document.inspect`, run at once on the document before the merge |
| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick\|tripleclick, x, y, space?: "doc"\|"screen", mods?}]}` | drive the active tool exactly like the mouse (`doubleclick` follows the second click's `up`, and `tripleclick` the third's): `mods.cmd` held at a press with any tool but a selection tool drags with the selection tool chosen last (Direct Selection with the Pen until one is); with Direct Selection or Group Selection it drags with the Selection tool (with Direct Selection and `mods.alt` held too, with Group Selection), and with the Selection tool it drags with Direct Selection or Group Selection, whichever was chosen last, except on a selected object (or a group holding a selected member) with another object under the pointer, away from its anchors, direction handles, mesh points, blend spine and the bounding box's handles and rotate zones while `ctrlClickSelectsBehind` is on, where the press selects the object behind; the release gives the tool back as it was; the reply lists `selection`, `key` (the key object, null without one) and `tool`. With the Shape Builder or the Live Paint Bucket and a selection of more than 128 segments, the app finds the regions off the UI thread, so a `move` replies before the region under the pointer is highlighted, and the highlight shows in the first frame after the regions are found. With the Shape Builder and such a selection, the app also merges off the UI thread: the reply to the events that end a click or drag comes once the merge is applied. A click or drag made before the regions are found does not wait for them; the app records it and makes it once they are found. Until then the canvas keeps drawing, with the touched regions highlighted and the busy pointer. A click or drag sent meanwhile, with `mods.cmd` too, and the Shape Builder's arrow keys are made after the merge in the order sent, and the reply to such a request comes once its events are made and any merge they start is applied; a request of `move` events alone is answered at once. A command that can edit, select, save or redraw the documents (an edit, an undo, a selection, a save or an export, a tool option, another tool, another document, closing, a dialog's preview, a menu item, a command of the app's own such as `ui.recolorDialog`, the proof and separations views, a preference, added fonts) waits for the merge and the input sent before it, and runs after them; queries that only read, such as `document.inspect`, run at once on the document before the merge |
| `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | synthetic keyboard input |
| `ui.move` | `{x, y}` | screen-point pointer move |
| `ui.click` / `ui.drag` | `{x, y, button?, count?, shift?, alt?, ctrl?, cmd?}` / `{x, y, toX, toY, steps?, count?, button?, shift?, alt?, ctrl?, cmd?}` | egui pointer input; see synthetic input budgets above |
+9 -1
View File
@@ -7248,7 +7248,15 @@ there too and a `brush.freehand` call does not change the path's brush or the se
A `pointer_gesture` with `mods: {cmd: true}` held at the press, with any tool but the selection tools (Command on
macOS, Ctrl elsewhere), drags with the selection tool chosen last (`select_tool`), or Direct Selection with the Pen,
Curvature and anchor tools until one is chosen; the release gives the tool back as it was, so the Pen goes on drawing
the path it had begun while that stays selected. Its reply's `tool` is the tool given back.
the path it had begun while that stays selected. With Direct Selection or Group Selection, `mods.cmd` drags with the
Selection tool (with Direct Selection and `mods.alt` held too, with Group Selection). With the Selection tool, it drags
with Direct Selection or Group Selection, whichever was chosen last (Direct Selection until one is), except where the
press lands on a selected object, or on a group holding a selected member, with another object under the pointer, away
from its anchors, direction handles, mesh points, blend spine and the bounding box's handles and rotate zones, while
`ctrlClickSelectsBehind` is on: there the Selection tool keeps the press and selects the object behind. A double-click
or triple-click made with Cmd still held after Cmd-clicks goes to the tool the clicks went to, and one that follows a
Cmd-click selecting behind keeps what that click selected, without isolating or editing. Its reply's `tool` is the tool
given back.
`tool.selectLastSelection` (Select Last Selection Tool, `{}`) chooses the selection tool chosen last, as Ctrl+` does on
Windows and Linux ([the help page](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) lists the
+1 -1
View File
@@ -1542,7 +1542,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Composition's leading-space reduction stays along the line when a character rotates. An opening bracket trimmed by Line-end Punctuation Half Width Mojikumi keeps that placement under Character Rotation; its turning point follows the composition adjustment, and removing the rotation keeps the trim. Scores and estimates are unchanged.
A character rotated near or at a quarter turn follows a Touch Type drag across its line as well as along it: baseline shift moves a character up from its line at any rotation, and the character turns about its shifted pen position.
Right-to-left characters can also move along their line when a preceding logical character is on that line. Positive `text.touchType` `dx` follows reading order, toward the left in horizontal right-to-left text; the first logical character still moves only up and down. These direction rules are VectorCraft's choices; the public Touch Type page describes moving a character without specifying this case. Scores and estimates are unchanged.
- **Temporary tools:** Cmd with any other tool drags with the selection tool used last (Selection, Direct Selection or Group Selection). Held Space pans and Cmd+Space zooms (Cmd+Alt+Space out) whatever the tool. A single-key tool shortcut held for 0.25 s or more, or held while its tool is used, chooses that tool only until the key is let go, and the tool active before comes back (after a drag in progress ends); a quicker press chooses the tool for good. This is VectorCraft's own rule and its own threshold, and General › Hold a Tool Shortcut to Use the Tool Temporarily (`holdToolKeys`, on by default) turns it off.
- **Temporary tools:** Cmd with any other tool drags with the selection tool used last (Selection, Direct Selection or Group Selection). With the Selection tool, Cmd lends Direct Selection or Group Selection, whichever was chosen last, until the key is released; with Group Selection it lends the Selection tool. A Cmd press on a selected object, or on a group holding a selected member, with another object under the pointer and away from its anchors, direction handles, mesh points, blend spine and the bounding box's handles and rotate zones, keeps Select Behind while Command Click to Select Objects Behind is on, as "Select behind an object" (Ctrl+click twice) in [Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) lists (#5970, #6583). Held Space pans and Cmd+Space zooms (Cmd+Alt+Space out) whatever the tool. A single-key tool shortcut held for 0.25 s or more, or held while its tool is used, chooses that tool only until the key is let go, and the tool active before comes back (after a drag in progress ends); a quicker press chooses the tool for good. This is VectorCraft's own rule and its own threshold, and General › Hold a Tool Shortcut to Use the Tool Temporarily (`holdToolKeys`, on by default) turns it off.
Space held while the Zoom tool drags a marquee moves the marquee and keeps its size ([Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)). When Space is let go, the drag sizes the marquee again from where it moved to.
A Space+Shift drag rotates the view whatever the tool, as a Rotate View tool drag does, and Shift does not round the angle to 15°.
While the Type tool edits text, Space types a space: held, it does not show the hand, pan or rotate the view, and Cmd+Space still zooms ([the help page](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) lists the Spacebar as the Hand tool when not in text-edit mode). Test: `canvas::tests::space_types_a_space_while_editing_text_and_does_not_pan`.
+1 -1
View File
@@ -366,7 +366,7 @@ tools, never checked side by side) isn't captured row by row.
| Space: Hand; Cmd+Space / Cmd+Alt+Space: zoom in/out; middle button pans | done | Space pressed after a tool takes a drag keeps the view still and shows that tool's cursor. Shape and anchor tools may use Space to move the geometry being drawn. Cmd+Space pressed mid-drag likewise keeps the active tool cursor. Space held before a press starts a view gesture, and its view cursor returns after release. `space_during_a_pencil_drag_keeps_the_pencil_cursor`, `cmd_space_mid_tool_drag_keeps_the_active_tool_cursor` |
| Document window scroll bars along the right and bottom edges (Normal and Full Screen Mode with Menu Bar; none in Full Screen and Presentation Mode): a thumb as long as the view against the art and the artboards; dragging it scrolls, a click on the track pages, the wheel over a bar scrolls along it; in a rotated view they follow the screen's axes | partial | #2322. The span is the art and the artboards with half a window around them, not Illustrator's 227 in canvas: VectorCraft has no bounded drawing area (#2284). A track click pages rather than jumping to the click; the page size and the rotated-view behaviour are our own choice (the public documentation gives neither) |
| A tool drag held near an edge of the canvas scrolls the view (#8551): zoomed in, a selection moved, a shape drawn or a marquee dragged towards the panels goes on past what shows | partial | Within 24 points of the canvas edge, once the pointer has moved 3 points from the press, the view scrolls away from that edge, faster nearer it (up to 900 points a second at the edge, and no faster in a corner, where it scrolls both ways), and keeps scrolling while the pointer stays still; the tool gets the pointer's new place in the document, so moved art stays under the pointer. Back away from the edge it stops. A click near the edge, the Hand, Zoom and Rotate View drags and Space panning do not scroll. The pointer past the canvas edge does not scroll: over a panel the Selection tools hand the art to the panels (#2826). The zone and speeds are VectorCraft's own (the public documentation gives none). Tests: `canvas::tests_edge_scroll` |
| Cmd/Ctrl: last-used selection tool; Cmd+Alt: Group Selection inside Direct Selection | done | Cmd+Alt lends Group Selection only while Direct Selection is active (Cmd borrow from the Pen keeps Direct Selection so Alt stays copy/subtract); Cmd alone lends Direct Selection the Selection tool: its bounding box shows while Cmd is held over objects selected whole and its handles scale and rotate them, and a Cmd drag moves the whole object while its direct-selected anchors stay selected (#3901; no box over a selection with anchors picked yet); engine pointer and canvas regressions |
| Cmd/Ctrl: last-used selection tool; Cmd+Alt: Group Selection inside Direct Selection | done | Cmd+Alt lends Group Selection only while Direct Selection is active (Cmd borrow from the Pen keeps Direct Selection so Alt stays copy/subtract); Cmd alone lends Direct Selection the Selection tool: its bounding box shows while Cmd is held over objects selected whole and its handles scale and rotate them, and a Cmd drag moves the whole object while its direct-selected anchors stay selected (#3901; no box over a selection with anchors picked yet); Cmd lends Group Selection the Selection tool, and the Selection tool Direct Selection or Group Selection, whichever was chosen last, except that a Cmd press on a selected object, or on a group holding a selected member, with another object under the pointer and away from its anchors, direction handles, mesh points, blend spine and the bounding box's handles and rotate zones, still selects the object behind it while Command Click to Select Objects Behind is on, so repeated Cmd-clicks select behind as "Select behind an object" (Ctrl+click twice, Command+click twice on macOS) in [Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) lists; Cmd pressed once a drag is under way lends nothing; while Cmd is held, the status bar's Current Tool and the help bar name the tool a press at the pointer takes; engine pointer and canvas regressions |
| Eyedropper copies effective character dimensions between transformed text objects | done | Point/area and grouped text, highlighted ranges, reverse/remembered sampling, opt-outs and atomic invalid-transform rejection; `scaled_type_pick_*` (#6404) |
| Eyedropper styles highlighted characters only and preserves ranges across Type switches | done | Font/paint, Shift color-only, Unicode, Undo/Redo and stale-range regression tests; enabled non-neutral source or target object transparency is refused atomically; disable Transparency to sample supported attributes |
| Gradient mesh: a solid color dropped from the Color or Swatches panel or a Fill proxy on a selected mesh recolors the mesh point under the pointer, else the patch's four points; with the mesh selected, an Eyedropper click applies the fill color the same way | done | [Edit mesh objects](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=312); `object.mesh.setPointColor`, one undo step, none when the color is unchanged. The 5-pixel reach for a point is VectorCraft's own. Tests `a_color_dropped_on_a_selected_mesh_recolors_the_point_or_patch_under_it`, `a_click_on_a_selected_mesh_gives_its_point_or_patch_the_fill_color`, `a_click_on_an_object_over_a_selected_mesh_copies_that_object` |