diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 7c0de44cab..8f96d46df2 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -189,7 +189,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()) } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e2e329dae1..bbcba38fff 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -113,9 +113,10 @@ pub struct Session { /// triple-click that follows it. None when the press was not lent. pub(crate) press_lent: Option<&'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). None when it was last asked + /// 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>, + 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. diff --git a/crates/engine/src/tests/draw2.rs b/crates/engine/src/tests/draw2.rs index f53a55e1e4..3ffd8e4576 100644 --- a/crates/engine/src/tests/draw2.rs +++ b/crates/engine/src/tests/draw2.rs @@ -4786,11 +4786,21 @@ fn a_cmd_press_on_a_selected_object_keeps_select_behind() { 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. + // 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(); @@ -4833,6 +4843,186 @@ fn a_cmd_press_on_a_wide_strokes_outer_half_selects_behind() { assert!(picked.contains(back) && !picked.contains(front), "the Cmd-click selects the object behind"); } +#[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 diff --git a/crates/engine/src/tests/dynamic_symbols.rs b/crates/engine/src/tests/dynamic_symbols.rs index e136d9f45b..7365d00c34 100644 --- a/crates/engine/src/tests/dynamic_symbols.rs +++ b/crates/engine/src/tests/dynamic_symbols.rs @@ -1032,6 +1032,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(); diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index ba4f4089e4..d9c2e6e4dc 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -10,6 +10,14 @@ use vectorcraft_tools::{Action, Cursor, ImeSurrounding, Mods, Overlay, PointerEv use crate::{EngineError, Prefs, Result, Session}; +/// What a hover's lend decision holds for ([`Session::hover_tool_at`]): the active document's uid +/// and revision, the active tool, the keys, the selection tools chosen last and the preferences a +/// press's hit test reads (Command Click to Select Objects Behind, Object Selection by Path Only, +/// Type Object Selection by Path Only, Selection Tolerance, anchor Size; Use Preview Bounds, +/// Measure Type by Glyph Bounds, Show Handles When Multiple Anchors Are Selected). +pub(crate) type HoverKey = + (Option<(u64, u64)>, &'static str, Mods, (Option<&'static str>, Option<&'static str>), ((bool, bool, bool, f64, u32), (bool, bool, bool))); + /// The tool whose radius is General › Corner Radius. const ROUNDED_RECTANGLE: &str = "roundedRectangle"; @@ -290,9 +298,9 @@ impl Session { /// 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, it still names the tool Cmd lends elsewhere. + /// 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.lent_tool_id(mods) { + match self.hovered_lent(mods) { Some(id) if !mods.space && !self.tool_editing() && !self.pointer_held => id, _ => self.tool.id(), } @@ -303,13 +311,40 @@ impl Session { /// (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 { - let lent = self.hover_lent.unwrap_or_else(|| self.lent_tool_id(mods)); - match lent { + 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; + let picks = + (p.ctrl_click_selects_behind, p.object_selection_by_path_only, p.type_selection_by_path_only, p.selection_tolerance, p.anchor_size); + let bounds = (p.use_preview_bounds, p.type_glyph_bounds, p.show_handles_multiple_anchors); + ( + self.active().map(|d| (d.uid, d.revision)), + self.tool.id(), + *mods, + (self.last_selection_tool, self.last_part_selection_tool), + (picks, bounds), + ) + } + /// 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 @@ -321,7 +356,8 @@ impl Session { Some(p) => self.lent_tool_at(p, mods, view), None => self.lent_tool_id(mods), }; - self.hover_lent = lends.then_some(lent); + let key = self.hover_key(mods); + self.hover_lent = lends.then_some((key, lent)); lent.unwrap_or(self.tool.id()) } @@ -1404,7 +1440,8 @@ impl Session { // 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 }; - self.hover_lent = lends.then_some(lent); + let key = self.hover_key(&mods); + self.hover_lent = lends.then_some((key, lent)); let c = match lent { Some(id) => { let lent = self.make_tool(id); diff --git a/crates/tools/src/direct.rs b/crates/tools/src/direct.rs index 7b224e0717..e4a0d85829 100644 --- a/crates/tools/src/direct.rs +++ b/crates/tools/src/direct.rs @@ -444,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)))) }) @@ -597,21 +602,23 @@ fn hit_anchor(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, usize, us }) } -/// Is `p` on a part of a selected object that Direct Selection edits: a gradient mesh point, a -/// blend's spine point or segment, an anchor, the end of a direction handle or a segment, within -/// the selection tolerance? A selected group or compound path counts through the editable paths -/// inside it. +/// 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() - || selected_spines(cx).iter().any(|(_, path)| path.anchors().any(|(_, _, a)| a.p.distance(p) <= tol)) - || hit_spine_segment(cx, p, seg_tol).is_some() - { + 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 @@ -630,13 +637,12 @@ pub fn over_selected_part(cx: &ToolContext, p: Point) -> bool { } v.into() }); - let reach = tol.max(seg_tol); boxes.iter().any(|&(id, b)| { - b.inflate(reach, reach).contains(p) + 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() || pd.nearest(p).is_some_and(|(.., d)| d <= seg_tol) + nearest_anchor(&pd, p, tol, None).is_some() }) }) } diff --git a/crates/tools/src/direct/tests.rs b/crates/tools/src/direct/tests.rs index 3cef62fab1..a9d5aab0c5 100644 --- a/crates/tools/src/direct/tests.rs +++ b/crates/tools/src/direct/tests.rs @@ -2821,3 +2821,30 @@ fn over_selected_part_measures_only_the_paths_near_the_pointer() { 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"); +} diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs index 458ac68232..38040162aa 100644 --- a/crates/tools/src/select.rs +++ b/crates/tools/src/select.rs @@ -224,6 +224,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, + /// 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. @@ -513,20 +518,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, measure: vectorcraft_effects::preview::Measure, bounds: Option>, oriented: Option>, by_object: HashMap>>, - /// [`painted_bounds`]. - painted: Option>, + /// [`painted_bounds`] in Preview and in Outline view. + painted: [Option>; 2], /// [`selected_part_boxes`]. part_boxes: Option>, + /// [`selection_holders`]. + holders: Option>>, + /// [`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, + 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 } } @@ -548,13 +600,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, + 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()); @@ -569,10 +624,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 } @@ -600,10 +661,39 @@ pub fn selection_box(cx: &ToolContext) -> Option { remembered(cx, |m| &mut m.oriented, || vectorcraft_effects::preview::oriented_bounds_with(cx.doc, &cx.selection.objects, cx.bounds_measure())) } -/// The selection's visual bounds as drawn, its strokes and effects included, whatever Use Preview -/// Bounds says: every point where a hit test finds a selected object is inside them. +/// 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 { - remembered(cx, |m| &mut m.painted, || vectorcraft_effects::preview::bounds_of(cx.doc, &cx.selection.objects, true)) + 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 = 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 @@ -819,6 +909,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 { @@ -1080,10 +1189,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 { 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); @@ -1146,6 +1261,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) { @@ -1518,26 +1634,103 @@ impl Tool for SelectionTool { } } -/// Does a Cmd/Ctrl press at `p` with the Selection tool select behind: is Select Behind on and a -/// selected object under the pointer, away from the anchors, handles and segments Direct -/// Selection edits ([`crate::direct::over_selected_part`])? Elsewhere Cmd lends the press to -/// Direct Selection or Group Selection. +/// 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 selection's painted bounds 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. - cx.select_behind - && painted_bounds(cx).is_some_and(|b| b.inflate(tol, tol).contains(p)) - && objects_at(cx.doc, p, cx.selection_hit_options(), cx.isolation).iter().any(|id| cx.selection.contains(*id)) - && !crate::direct::over_selected_part(cx, p) + // 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 } -/// 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. +/// 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 { + 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> { + 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 { + 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 = 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 { 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() } @@ -1853,6 +2046,14 @@ impl SelectionTool { fn double_click(&mut self, cx: &ToolContext, p: Point, m: Mods) -> Vec { 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) { diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index cd375d0952..e44d7013d1 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1653,7 +1653,17 @@ pub(super) fn guide_labels(doc: &vectorcraft_doc::Document) -> std::collections: /// the pointer is not hit-tested again (#2452), and the last answer stays. fn marks_tool(app: &mut VectorcraftApp, ctx: &egui::Context, hover_still: bool, view: vectorcraft_engine::ViewInfo) -> &'static str { let held = held_mods(app, ctx); - if hover_still { app.session.hover_tool_at(app.hover_doc, &held, view) } else { app.session.hover_tool_id(&held) } + if !hover_still { + return app.session.hover_tool_id(&held); + } + let named = app.session.shown_tool_id(&held); + let tool = app.session.hover_tool_at(app.hover_doc, &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(); + } + tool } /// The selection's visuals and the tools' overlays, to be drawn. `tool` is the tool whose marks diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 508ccb03a0..21dd33b715 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -7159,6 +7159,111 @@ fn blend_widgets_hide_while_cmd_lends_direct_selection() { assert_eq!(widgets(&mut app, egui::Modifiers::NONE), plain, "back when the key is let go"); } +/// One canvas frame with `modifiers` held and, when given, the pointer moved to `pointer` (in +/// screen points) → the shapes drawn, with the ones in shape lists listed one by one. +fn drawn_with(app: &mut VectorcraftApp, ctx: &egui::Context, modifiers: egui::Modifiers, pointer: Option) -> Vec { + app.canvas.selection_marks = Default::default(); + let mut events = vec![egui::Event::ModifiersChanged(modifiers)]; + events.extend(pointer.map(egui::Event::PointerMoved)); + let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), events, ..Default::default() }; + let mut out = ctx.run_ui(raw, |ui| show(app, ui)); + out.textures_delta.clear(); + let mut drawn = vec![]; + for c in out.shapes { + match c.shape { + Shape::Vec(v) => drawn.extend(v), + s => drawn.push(s), + } + } + drawn +} + +/// 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. +#[test] +fn selection_tool_widgets_hide_while_cmd_lends_direct_selection() { + let ctx = egui::Context::default(); + let count = |app: &mut VectorcraftApp, modifiers: egui::Modifiers, is_widget: &dyn Fn(&Shape) -> bool| { + drawn_with(app, &ctx, modifiers, None).iter().filter(|s| is_widget(s)).count() + }; + // Each widget that does not draw, hide or come back as it should. + let mut wrong = vec![]; + let mut check = |app: &mut VectorcraftApp, what: &str, is_widget: &dyn Fn(&Shape) -> bool| { + app.select_tool("selection"); + let plain = count(app, egui::Modifiers::NONE, is_widget); + let held = count(app, egui::Modifiers::COMMAND, is_widget); + let back = count(app, egui::Modifiers::NONE, is_widget); + if plain == 0 || held != 0 || back != plain { + wrong.push(format!("{what}: {plain} drawn, {held} with Cmd held, {back} after")); + } + }; + let new_app = || { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app + }; + let circle_of = |r: f32| move |s: &Shape| matches!(s, Shape::Circle(c) if c.radius == r); + + let mut app = new_app(); + for x in [0, 50] { + app.run("shape.rectangle", json!({"x": x, "y": 0, "width": 100, "height": 100})).unwrap(); + } + app.run("shaper.scribble", json!({"points": [[25, 20], [75, 35], [30, 50], [125, 65]]})).unwrap(); + check(&mut app, "the Shaper Group's mode widget", &circle_of(vectorcraft_tools::shaperwidget::RADIUS_PX)); + + let mut app = new_app(); + app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 60, "height": 80})).unwrap(); + app.run("object.repeat.mirror", json!({})).unwrap(); + let selection = Tokens::get(&ctx).selection; + check( + &mut app, + "the mirror axis", + &move |s: &Shape| matches!(s, Shape::LineSegment { stroke, .. } if stroke.color == selection && stroke.width == 2.0), + ); + + let mut app = new_app(); + app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 40, "height": 40})).unwrap(); + app.run("object.repeat.grid", json!({"hSpacing": 10, "vSpacing": 10})).unwrap(); + check(&mut app, "the grid repeat's handles", &circle_of(vectorcraft_tools::repeat_grid::HANDLE_RADIUS)); + + let mut app = new_app(); + app.run("shape.rectangle", json!({"x": 180, "y": 40, "width": 40, "height": 40})).unwrap(); + app.run("object.repeat.radial", json!({"instances": 6, "radius": 60})).unwrap(); + check(&mut app, "the radial repeat's handles", &circle_of(vectorcraft_tools::repeat_radial::HANDLE_RADIUS)); + assert!(wrong.is_empty(), "{}", wrong.join("\n")); +} + +/// The canvas decides which tool's widgets to draw for the pointer where it is in the same frame: +/// over the selected blend a Cmd press selects behind, so the Selection tool's blend widgets stay; +/// moved away in the next frame, where Cmd lends Direct Selection, they hide in that frame. +#[test] +fn the_widgets_follow_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 = egui::Context::default(); + let r = vectorcraft_tools::blendwidget::RADIUS_PX; + let widgets = |app: &mut VectorcraftApp, modifiers: egui::Modifiers, at: Option| { + let pointer = at.map(|p| Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()).to_screen(p)); + drawn_with(app, &ctx, modifiers, pointer).iter().filter(|s| matches!(s, Shape::Circle(c) if c.radius == r)).count() + }; + let plain = widgets(&mut app, egui::Modifiers::NONE, None); + assert!(plain >= 2, "the Appearance and Easing widgets: {plain}"); + // Inside the first key object, away from its anchors and the spine. + let over = widgets(&mut app, egui::Modifiers::COMMAND, Some(Point::new(80.0, 175.0))); + assert_eq!(over, plain, "over the selected blend, the press selects behind"); + let away = widgets(&mut app, egui::Modifiers::COMMAND, Some(Point::new(200.0, 380.0))); + assert!(away + 2 <= plain, "away from it, hidden in the same frame: {away} of {plain}"); +} + /// A selected Objects on Path group shows its Rotate All widget with the Selection and Objects on /// Path tools. #[test] diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 58c13dbe9b..3727b6c798 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -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); with Direct Selection or Group Selection it drags with the Selection tool, and with the Selection tool it drags with Direct Selection or Group Selection, whichever was chosen last, except on a selected object away from its anchors, handles and segments 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.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 | diff --git a/docs/mcp.md b/docs/mcp.md index 5032690fc6..4f3c98abb7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7080,7 +7080,14 @@ 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 diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f8a3dc84a0..817e79d3ac 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1523,7 +1523,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 (#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`. diff --git a/docs/ui-parity.md b/docs/ui-parity.md index f9f140fc76..8fdb42793c 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -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); 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, away from its anchors, handles and segments, still selects the object behind it while Command Click to Select Objects Behind is on; 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 it lends ([Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), "Work with selections"); 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` |