From 5433e02d8e2512f1ffd478cedf39d44bb74a1e3b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 13:21:04 -0800 Subject: [PATCH 1/3] Selection: a click inside an unfilled closed shape selects it With Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection now pick a closed path or compound path that has no fill by a click inside its closed subpaths. Before, such a shape could only be picked on its path, and a click inside started a marquee. The inside counts only where no other object is hit: a click first looks for what paints at the point, the same as before, and only then for the topmost unfilled closed shape around it, so art drawn inside a frame is still picked before the frame. Select Behind lists those shapes after the objects that paint there, and Direct Selection in a dynamic symbol's art picks parts in the same order. Open paths, guides and clipping paths are still picked by their path only, and Outline view is unchanged. With Object Selection by Path Only on, the inside of an unfilled shape takes no click, as before. Three tests clicked inside an unfilled square and expected nothing to be selected: the Selection and Direct Selection center point tests and the outside-stroke reach test. They now run with Object Selection by Path Only on, and the Direct Selection and stroke reach tests also check that the click selects the square with it off. Fixes #9175 --- crates/doc/src/hit.rs | 130 +++++++++++++++++--- crates/doc/src/hit/tests.rs | 163 +++++++++++++++++++++++++ crates/engine/src/tests/strokereach.rs | 6 + crates/mcp/src/tests.rs | 26 ++++ crates/tools/src/context.rs | 8 +- crates/tools/src/direct/tests.rs | 9 +- crates/tools/src/select/tests.rs | 5 +- crates/ui-egui/src/canvas/outline.rs | 9 +- docs/mcp.md | 3 + docs/target-app-parity.md | 2 + 10 files changed, 332 insertions(+), 29 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 6d5cb0f1a5..a69308968c 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -81,6 +81,11 @@ pub struct HitOptions { /// The point hit tests ([`hit_test`], [`hit_test_visible`] and [`hit_test_visible_skipping`]) /// hit the art on a layer whose Preview is off as painted, not in outline. pub ignore_layer_preview: bool, + /// The selection tools: where a click hits nothing else, a closed path or compound path with + /// no fill is hit inside its closed subpaths, the topmost first, as a filled one is. Off with + /// [`Self::path_only`] and in outline. Clipping paths and guides are still hit on their + /// outline only. [`hit_test`] and [`objects_at`] try every other object first. + pub unfilled_interiors: bool, } impl Default for HitOptions { @@ -94,6 +99,7 @@ impl Default for HitOptions { clip_outlines: false, area_type_interior: false, ignore_layer_preview: false, + unfilled_interiors: false, scope: None, } } @@ -417,11 +423,35 @@ impl Drop for DrawnOff { } } +thread_local! { + /// Whether a clipping path is being tested ([`InMask`]). + static IN_MASK: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// While a guard lives, a clipping path is tested: it is not hit inside by its interior alone +/// ([`takes_interior`]). +struct InMask { + was: bool, +} + +impl InMask { + fn set() -> Self { + Self { was: IN_MASK.replace(true) } + } +} + +impl Drop for InMask { + fn drop(&mut self) { + IN_MASK.set(self.was); + } +} + /// `f()`, with `mask` under a [`DrawnOff`] guard: the clipping path of a clip group or of a /// clipping layer is clicked and touched by its own geometry, whatever its geometry effects do to -/// the region it clips to. +/// the region it clips to. It is also under an [`InMask`] guard. fn plain(mask: bool, f: impl FnOnce() -> T) -> T { let _off = mask.then(DrawnOff::set); + let _mask = mask.then(InMask::set); f() } @@ -636,17 +666,23 @@ pub fn objects_at(doc: &Document, p: Point, opt: HitOptions, scope: Option bool, editable_only: bool) -> Option { + let painted = hit_test_walk(doc, p, HitOptions { unfilled_interiors: false, ..opt }, skip, editable_only); + if painted.is_some() || !opt.unfilled_interiors || opt.path_only || opt.outline { + return painted; + } + hit_test_walk(doc, p, opt, skip, editable_only) +} + +/// One walk of [`hit_test_skipping`], with `opt` as given. +fn hit_test_walk(doc: &Document, p: Point, opt: HitOptions, skip: &dyn Fn(NodeId) -> bool, editable_only: bool) -> Option { let _walk = ArtWalk::open(); let finish = |mut h: Hit| { h.contents_of = h.ancestry.iter().rev().copied().find(|a| doc.node(*a).is_some_and(edits_contents)); @@ -1378,7 +1425,10 @@ fn art_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, accept: & return false; } } - hit_order(n, children, p).any(|i| children.get(i).is_some_and(|c| !shaper_hides(n, i, None) && art_hit(c, p, opt, symbols, accept))) + hit_order(n, children, p).any(|i| { + let _mask = (i == 0 && n.clips()).then(InMask::set); + children.get(i).is_some_and(|c| !shaper_hides(n, i, None) && art_hit(c, p, opt, symbols, accept)) + }) } _ => hit_leaf(n, p, opt, symbols).is_some_and(|kind| accept(n.id, kind)), } @@ -1467,6 +1517,8 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio match &n.kind { NodeKind::Path { path, rule, .. } => { let has_fill = n.appearance.has_visible_fill(); + let interior = !has_fill && path.subpaths.iter().any(|sp| sp.closed) && takes_interior(n, opt); + let inside = || (interior && fill_contains(&closed_subpaths_at([path], p), *rule, p)).then_some(HitKind::Fill); if opt.outline && let Some((hit, needs_full_check)) = near_path_body(path, p, opt.tol, 0.0) { @@ -1501,7 +1553,7 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio return Some(HitKind::Stroke); } if !near_decoration { - return None; + return inside(); } } let bp = path.to_bezpath(); @@ -1511,7 +1563,7 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio if !opt.outline && !opt.path_only && has_fill && fill_contains(&bp, *rule, p) { return Some(HitKind::Fill); } - None + inside() } NodeKind::Compound { children, rule } => { // Painted strokes follow the whole compound path (alignment, dashes, width profiles): @@ -1529,7 +1581,11 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio if vectorcraft_geom::hit::distance_to_outline(&near, p) <= opt.tol { return Some(HitKind::Outline); } - (!opt.outline && !opt.path_only && n.appearance.has_visible_fill() && fill_contains(&near, *rule, p)).then_some(HitKind::Fill) + if n.appearance.has_visible_fill() { + return (!opt.outline && !opt.path_only && fill_contains(&near, *rule, p)).then_some(HitKind::Fill); + } + let closed = || closed_subpaths_at(children.iter().filter_map(|m| m.path_data()), p); + (takes_interior(n, opt) && fill_contains(&closed(), *rule, p)).then_some(HitKind::Fill) } // The type path lies within the bounds: they rule out the rest before it is measured. NodeKind::Text(t) if opt.type_path_only => { @@ -1601,6 +1657,30 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio } } +/// Is path or compound path `n`, which has no visible fill, hit inside its closed subpaths +/// ([`HitOptions::unfilled_interiors`])? Not a clipping path ([`InMask`]) or a guide. +fn takes_interior(n: &Node, opt: HitOptions) -> bool { + opt.unfilled_interiors + && !opt.outline + && !opt.path_only + && !IN_MASK.get() + && !matches!(n.kind, NodeKind::Path { clipping: true, .. } | NodeKind::Path { guide: true, .. }) +} + +/// The closed subpaths of `paths` whose control points' box holds `p`, as one path. A path outside +/// that box winds zero times round `p`, so this path's fill holds `p` as all the closed subpaths' +/// fill does. Open subpaths are left out: they bound no area. +fn closed_subpaths_at<'a>(paths: impl IntoIterator, p: Point) -> BezPath { + let holds = |b: Rect| b.x0 <= p.x && p.x <= b.x1 && b.y0 <= p.y && p.y <= b.y1; + let mut bp = BezPath::new(); + for pd in paths.into_iter().filter(|pd| pd.control_bounds().is_some_and(holds)) { + for sp in pd.subpaths.iter().filter(|sp| sp.closed) { + sp.to_bezpath_into(&mut bp); + } + } + bp +} + /// What a click at `p` hits among the shapes that the fills and strokes of `n` (an image or a /// symbol instance) paint with their geometry effects ([`image_paint`]), the frontmost first: a /// stroke along its shape, a fill inside it except with Selection by Path Only. @@ -1877,13 +1957,23 @@ fn moved(n: &Node, xf: vectorcraft_geom::Affine) -> Node { /// (blends, envelopes, repeats) are tested without those effects. `None` when `inst` is not a /// symbol instance or no editable object of its art is under `p`. pub fn symbol_part_at(doc: &Document, inst: &Node, p: Point, opt: HitOptions) -> Option> { - let _walk = ArtWalk::open(); + let walk = ArtWalk::open(); let outline = opt.outline || below_preview_off(doc, inst, opt.scope); let art = InstanceArt::drawn(doc, inst, outline)?; let symbols = doc.kept_symbol_boxes(); - let mut path = vec![]; - let find = FindPart { art: &art, p, opt, symbols: &symbols, whole_instance: false, drawn: true }; - find.find(&art.art, &mut path, None, outline).map(|_| path) + let pick = |opt: HitOptions| { + let mut path = vec![]; + let find = FindPart { art: &art, p, opt, symbols: &symbols, whole_instance: false, drawn: true }; + find.find(&art.art, &mut path, None, outline).map(|_| path) + }; + // As [`hit_test`] does: inside an unfilled closed path only where nothing else is hit. + pick(HitOptions { unfilled_interiors: false, ..opt }).or_else(|| { + if !opt.unfilled_interiors || opt.path_only || outline { + return None; + } + walk.restart(); + pick(opt) + }) } /// The walk of a symbol instance's placed art that [`symbol_part_at`] and [`instance_art_hit`] make. diff --git a/crates/doc/src/hit/tests.rs b/crates/doc/src/hit/tests.rs index a16b3ad149..5aa7dac4ee 100644 --- a/crates/doc/src/hit/tests.rs +++ b/crates/doc/src/hit/tests.rs @@ -38,6 +38,168 @@ fn unfilled_interior_misses() { assert!(hit_test(&d, Point::new(50.5, 25.0), HitOptions::default()).is_some()); } +/// The selection tools' options with unfilled closed paths hit inside. +const INTERIORS: HitOptions = HitOptions { unfilled_interiors: true, ..SELECTING }; + +/// A path of `points` with a black stroke and no fill, inserted at the top of the first layer. +fn stroked(d: &mut Document, points: &[(f64, f64)], closed: bool) -> NodeId { + let l = d.layers[0].id; + let id = d.alloc_id(); + let pts: Vec = points.iter().map(|&(x, y)| Point::new(x, y)).collect(); + let path = vectorcraft_geom::PathData::single(vectorcraft_geom::SubPath::polyline(&pts, closed)); + d.insert(Some(l), 99, Node::path(id, path, Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0))).unwrap(); + id +} + +const FRAME: [(f64, f64); 4] = [(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)]; + +#[test] +fn an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline() { + let mut d = Document::new(200.0, 200.0); + let frame = stroked(&mut d, &FRAME, true); + let at = |opt: HitOptions| hit_test(&d, Point::new(50.0, 50.0), opt).map(|h| h.leaf); + assert_eq!(at(INTERIORS), Some(frame)); + assert_eq!(at(SELECTING), None, "without the option, the interior misses"); + assert_eq!(at(HitOptions { path_only: true, ..INTERIORS }), None, "Object Selection by Path Only"); + assert_eq!(at(HitOptions { outline: true, ..INTERIORS }), None, "Outline view"); + assert_eq!(objects_at(&d, Point::new(50.0, 50.0), INTERIORS, None), vec![frame]); + assert!(objects_at(&d, Point::new(150.0, 50.0), INTERIORS, None).is_empty(), "outside it"); +} + +#[test] +fn an_open_path_is_not_hit_inside() { + let mut d = Document::new(200.0, 200.0); + stroked(&mut d, &FRAME, false); + assert_eq!(hit_test(&d, Point::new(50.0, 50.0), INTERIORS), None); +} + +/// What a click paints over comes first: an object drawn inside an unfilled frame above it is hit +/// where it paints, and the frame elsewhere inside; Select Behind lists the frame after it. +#[test] +fn art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame() { + let mut d = Document::new(200.0, 200.0); + let l = d.layers[0].id; + let dot = d.alloc_id(); + d.insert(Some(l), 0, Node::path(dot, shapes::rectangle(Rect::new(40.0, 40.0, 60.0, 60.0)), Appearance::default_art())).unwrap(); + let frame = stroked(&mut d, &FRAME, true); + let at = |d: &Document, x: f64| hit_test(d, Point::new(x, 50.0), INTERIORS).map(|h| h.leaf); + assert_eq!(at(&d, 50.0), Some(dot)); + assert_eq!(at(&d, 20.0), Some(frame)); + assert_eq!(objects_at(&d, Point::new(50.0, 50.0), INTERIORS, None), vec![dot, frame]); + // The topmost of two unfilled frames is hit inside both. + let inner = stroked(&mut d, &[(10.0, 10.0), (90.0, 10.0), (90.0, 90.0), (10.0, 90.0)], true); + assert_eq!(at(&d, 20.0), Some(inner)); + assert_eq!(at(&d, 5.0), Some(frame)); +} + +#[test] +fn an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes() { + let mut d = Document::new(200.0, 200.0); + let l = d.layers[0].id; + let look = || Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0); + let ring = |id, r: Rect| Arc::new(Node::path(id, shapes::rectangle(r), look())); + let (id, outer, hole) = (d.alloc_id(), d.alloc_id(), d.alloc_id()); + let members = vec![ring(outer, Rect::new(0.0, 0.0, 100.0, 100.0)), ring(hole, Rect::new(30.0, 30.0, 70.0, 70.0))]; + let mut compound = Node::new(id, NodeKind::Compound { children: members, rule: FillRule::EvenOdd }); + compound.appearance = look().into(); + d.insert(Some(l), 0, compound).unwrap(); + let at = |x: f64| hit_test(&d, Point::new(x, 50.0), INTERIORS).map(|h| h.leaf); + assert_eq!(at(15.0), Some(id)); + assert_eq!(at(50.0), None, "in the hole"); +} + +#[test] +fn guides_and_clipping_paths_are_not_hit_inside() { + let mut d = Document::new(200.0, 200.0); + let guide = stroked(&mut d, &FRAME, true); + if let Some(NodeKind::Path { guide: g, .. }) = d.node_mut(guide).map(|n| &mut n.kind) { + *g = true; + } + assert_eq!(hit_test(&d, Point::new(50.0, 50.0), INTERIORS), None, "a guide"); + // A clip group whose art covers only part of its unfilled clipping path. + let mut d = Document::new(200.0, 200.0); + let l = d.layers[0].id; + let (g, clip, art) = (d.alloc_id(), d.alloc_id(), d.alloc_id()); + let mut mask = Node::path(clip, shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)), Appearance::basic(Paint::None, Paint::None, 0.0)); + if let NodeKind::Path { clipping, .. } = &mut mask.kind { + *clipping = true; + } + let picture = Node::path(art, shapes::rectangle(Rect::new(0.0, 0.0, 50.0, 100.0)), Appearance::default_art()); + d.insert(Some(l), 0, Node::new(g, NodeKind::Group { children: vec![Arc::new(mask), Arc::new(picture)], clip: true })).unwrap(); + let at = |x: f64| hit_test(&d, Point::new(x, 50.0), INTERIORS).map(|h| h.leaf); + assert_eq!(at(25.0), Some(art)); + assert_eq!(at(75.0), None, "inside the mask where no art paints"); + assert!(objects_at(&d, Point::new(75.0, 50.0), INTERIORS, None).is_empty()); +} + +/// A repeat's copies of an unfilled frame are hit inside, and the copies of a clip group's unfilled +/// compound clipping path are not. +#[test] +fn a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks() { + let look = || Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0); + let kind = crate::pattern::RepeatKind::Grid { + h_spacing: 20.0, + v_spacing: 20.0, + rows: 1, + cols: 2, + grid_type: crate::pattern::TileType::Grid, + flip_rows: false, + flip_cols: false, + }; + let repeat = |d: &mut Document, source: Node| { + let r = d.alloc_id(); + let l = d.layers[0].id; + d.insert(Some(l), 0, Node::new(r, NodeKind::Repeat(crate::pattern::RepeatSpec { kind: kind.clone(), source: vec![Arc::new(source)] }))) + .unwrap(); + r + }; + // Copies at 0..40 and 60..100. + let mut d = Document::new(300.0, 200.0); + let frame = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 40.0, 40.0)), look()); + let r = repeat(&mut d, frame); + assert_eq!(hit_test(&d, Point::new(80.0, 20.0), INTERIORS).map(|h| h.leaf), Some(r)); + assert_eq!(hit_test(&d, Point::new(50.0, 20.0), INTERIORS), None, "between the copies"); + let mut d = Document::new(300.0, 200.0); + let ring = |id, r: Rect| Arc::new(Node::path(id, shapes::rectangle(r), look())); + let members = vec![ring(d.alloc_id(), Rect::new(0.0, 0.0, 40.0, 40.0)), ring(d.alloc_id(), Rect::new(5.0, 5.0, 35.0, 35.0))]; + let mut mask = Node::new(d.alloc_id(), NodeKind::Compound { children: members, rule: FillRule::NonZero }); + mask.appearance = look().into(); + let picture = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 40.0)), Appearance::default_art()); + let mut clip = Node::group(d.alloc_id(), vec![Arc::new(mask), Arc::new(picture)]); + clip.set_clips(true); + let r = repeat(&mut d, clip); + assert_eq!(hit_test(&d, Point::new(65.0, 20.0), INTERIORS).map(|h| h.leaf), Some(r), "on the clipped art"); + assert_eq!(hit_test(&d, Point::new(80.0, 20.0), INTERIORS), None, "inside the mask where no art paints"); +} + +/// Direct Selection in a dynamic symbol's art picks parts as a click on the document does: what +/// paints first, then an unfilled frame inside; an unfilled compound clipping path by its outline. +#[test] +fn symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints() { + let mut d = Document::new(300.0, 200.0); + let l = d.layers[0].id; + let look = || Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0); + let dot = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(40.0, 40.0, 60.0, 60.0)), Appearance::default_art()); + let frame = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 100.0)), look()); + let ring = |id, r: Rect| Arc::new(Node::path(id, shapes::rectangle(r), look())); + let (mask_id, a, b) = (d.alloc_id(), d.alloc_id(), d.alloc_id()); + let members = vec![ring(a, Rect::new(150.0, 0.0, 250.0, 100.0)), ring(b, Rect::new(160.0, 10.0, 240.0, 90.0))]; + let mut mask = Node::new(mask_id, NodeKind::Compound { children: members, rule: FillRule::NonZero }); + mask.appearance = look().into(); + let picture = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(150.0, 0.0, 180.0, 100.0)), Appearance::default_art()); + let mut clip = Node::group(d.alloc_id(), vec![Arc::new(mask), Arc::new(picture)]); + clip.set_clips(true); + let root = Node::group(d.alloc_id(), vec![Arc::new(dot), Arc::new(frame), Arc::new(clip)]); + d.symbols.push(crate::Symbol { dynamic: true, name: "Framed".into(), art: Arc::new(root) }); + let inst = d.alloc_id(); + d.insert(Some(l), 0, Node::new(inst, NodeKind::SymbolInstance { symbol: "Framed".into(), xf: vectorcraft_geom::Affine::IDENTITY })).unwrap(); + let n = d.node(inst).unwrap(); + let at = |x: f64| symbol_part_at(&d, n, Point::new(x, 50.0), INTERIORS); + assert_eq!(at(50.0), Some(vec![0]), "the dot under the frame"); + assert_eq!(at(20.0), Some(vec![1]), "inside the frame"); + assert_eq!(at(220.0), None, "inside the clipping path where no art paints"); +} + #[test] fn long_plain_stroke_hits_its_middle_and_curved_end() { let mut d = Document::new(200.0, 200.0); @@ -1464,6 +1626,7 @@ const SELECTING: HitOptions = HitOptions { clip_outlines: true, area_type_interior: false, ignore_layer_preview: false, + unfilled_interiors: false, scope: None, }; diff --git a/crates/engine/src/tests/strokereach.rs b/crates/engine/src/tests/strokereach.rs index 1154073a3b..a04388af89 100644 --- a/crates/engine/src/tests/strokereach.rs +++ b/crates/engine/src/tests/strokereach.rs @@ -52,6 +52,9 @@ fn a_click_outside_an_outside_stroke_selects_it() { s.execute("paint.setFill", &json!({"none": true})).unwrap(); s.execute("stroke.set", &json!({"weight": 20, "align": "outside"})).unwrap(); s.execute("select.none", &json!({})).unwrap(); + // Object Selection by Path Only: the inside of the unfilled square takes no click of its own, + // so only the stroke is tested. + s.execute("prefs.set", &json!({"key": "objectSelectionByPathOnly", "value": true})).unwrap(); // 0.8 × the weight outside the path: past where a centred stroke (plus the tolerance) reaches. assert_eq!(click(&mut s, 84.0, 200.0), [r]); s.execute("select.none", &json!({})).unwrap(); @@ -59,6 +62,9 @@ fn a_click_outside_an_outside_stroke_selects_it() { s.execute("stroke.set", &json!({"ids": [r.0], "align": "center"})).unwrap(); s.execute("select.none", &json!({})).unwrap(); assert!(click(&mut s, 84.0, 200.0).is_empty(), "a centred stroke doesn't reach"); + // With it off, a click inside the unfilled square selects it (#9175). + s.execute("prefs.set", &json!({"key": "objectSelectionByPathOnly", "value": false})).unwrap(); + assert_eq!(click(&mut s, 116.0, 200.0), [r]); } #[test] diff --git a/crates/mcp/src/tests.rs b/crates/mcp/src/tests.rs index c1a661c4e3..f36f35522a 100644 --- a/crates/mcp/src/tests.rs +++ b/crates/mcp/src/tests.rs @@ -1940,6 +1940,32 @@ fn selection_preferences_apply_to_pointer_gestures() { assert_eq!(click(&mut s, 7, 250.0, json!({})), json!([front]), "the path does"); } +/// A Selection tool click inside a closed shape with no fill selects it (#9175), and with Object +/// Selection by Path Only on it selects nothing. +#[test] +fn a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only() { + let mut s = server(); + let r = call( + &mut s, + 1, + "draw_shape", + json!({"shape": "rectangle", "x": 100, "y": 100, "width": 100, "height": 100, "fill": "none", "stroke": "#000000"}), + ); + let id = serde_json::from_str::(&text_of(&r)).unwrap()["id"].as_u64().unwrap(); + let click = |s: &mut Server, n: u64| { + let r = call(s, n, "run_command", json!({"command": "select.none", "params": {}})); + assert_eq!(r["isError"], false, "{r}"); + let events = json!([{"kind": "down", "x": 150, "y": 150}, {"kind": "up", "x": 150, "y": 150}]); + let r = call(s, n + 1, "pointer_gesture", json!({"tool": "selection", "events": events})); + assert_eq!(r["isError"], false, "{r}"); + serde_json::from_str::(&text_of(&r)).unwrap()["selection"].clone() + }; + assert_eq!(click(&mut s, 2), json!([id])); + let r = call(&mut s, 4, "run_command", json!({"command": "prefs.set", "params": {"key": "objectSelectionByPathOnly", "value": true}})); + assert_eq!(r["isError"], false, "{r}"); + assert_eq!(click(&mut s, 5), json!([]), "path only"); +} + #[test] fn pointer_gesture_forwards_backquote_on_each_event() { let mut s = server(); diff --git a/crates/tools/src/context.rs b/crates/tools/src/context.rs index 67658b4ea9..d168e7ca87 100644 --- a/crates/tools/src/context.rs +++ b/crates/tools/src/context.rs @@ -463,16 +463,20 @@ impl ToolContext<'_> { clip_outlines: false, area_type_interior: false, ignore_layer_preview: false, + unfilled_interiors: false, } } /// [`Self::hit_options`] for the selection tools (Selection, Direct Selection, Group - /// Selection): a clipping path is also hit on its outline ([`HitOptions::clip_outlines`]). + /// Selection): a clipping path is also hit on its outline ([`HitOptions::clip_outlines`]), and + /// where nothing else is hit, an unfilled closed path is hit inside unless Object Selection by + /// Path Only is on ([`HitOptions::unfilled_interiors`]). /// Only for what a press or a hover selects: a double-click, loaded text or a guide's release /// acts on what is drawn and takes [`Self::hit_options`]. /// /// [`HitOptions::clip_outlines`]: vectorcraft_doc::hit::HitOptions::clip_outlines + /// [`HitOptions::unfilled_interiors`]: vectorcraft_doc::hit::HitOptions::unfilled_interiors pub fn selection_hit_options(&self) -> vectorcraft_doc::hit::HitOptions { - vectorcraft_doc::hit::HitOptions { clip_outlines: true, ..self.hit_options() } + vectorcraft_doc::hit::HitOptions { clip_outlines: true, unfilled_interiors: true, ..self.hit_options() } } } diff --git a/crates/tools/src/direct/tests.rs b/crates/tools/src/direct/tests.rs index a39bf3766f..f049ab09bc 100644 --- a/crates/tools/src/direct/tests.rs +++ b/crates/tools/src/direct/tests.rs @@ -1735,13 +1735,18 @@ fn the_centre_point_selects_and_moves_the_object_whole() { let moved = json!({"matrix": matrix_json(vectorcraft_geom::Affine::translate(Vec2::new(20.0, -10.0))), "copy": false}); assert_eq!(a, vec![Action::Begin("Move".into()), Action::Preview("object.transform".into(), moved)]); assert_eq!(t.pointer(&c, &PointerEvent::new(PointerKind::Up, 170.0, 140.0)), vec![Action::Commit]); - // Unselected, the centre isn't shown and a press there starts a marquee. + // Unselected, the centre isn't shown and a press there starts a marquee (with Object Selection + // by Path Only, where the inside of the unfilled square takes no press). let none = Selection::default(); let mut t = DirectSelectionTool::new(false); - let c = cx(&d, &none, &p); + let c = ToolContext { path_only: true, ..cx(&d, &none, &p) }; assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, 150.0, 150.0)).is_empty()); t.pointer(&c, &PointerEvent::new(PointerKind::Drag, 170.0, 140.0)); assert!(t.overlays(&c).iter().any(|o| matches!(o, Overlay::Marquee(_)))); + // Without it, a press inside the unfilled square selects it (#9175). + let mut t = DirectSelectionTool::new(false); + let c = cx(&d, &none, &p); + assert_eq!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, 150.0, 150.0)), vec![Action::Exec("select.set".into(), json!({"ids": [id.0]}))]); } /// Group Selection: E pressed during a marquee drag makes it select the objects entirely inside diff --git a/crates/tools/src/select/tests.rs b/crates/tools/src/select/tests.rs index ff95ef68ce..d575fda573 100644 --- a/crates/tools/src/select/tests.rs +++ b/crates/tools/src/select/tests.rs @@ -2917,14 +2917,15 @@ fn a_double_click_on_a_symbol_instance_edits_its_symbol() { /// #4891 for the Selection tool: a press on a selected object's centre point (Attributes › Show /// Center) moves the selection, also where no art is painted (an unfilled shape), which the press -/// would otherwise take for a marquee; anywhere else a press still starts one. +/// would otherwise take for a marquee; anywhere else a press still starts one. With Object +/// Selection by Path Only, so that the inside of the unfilled shape takes no press of its own. #[test] fn a_press_on_the_centre_point_moves_an_unfilled_shape() { let (d, id) = doc_with_live_rect(); let mut s = Selection::default(); s.add(id); let p = paint(); - let c = cx(&d, &s, &p); + let c = ToolContext { path_only: true, ..cx(&d, &s, &p) }; let centre = Point::new(150.0, 150.0); let mut t = SelectionTool::default(); assert_eq!(t.cursor(&c, centre, Mods::default()), Cursor::Move); diff --git a/crates/ui-egui/src/canvas/outline.rs b/crates/ui-egui/src/canvas/outline.rs index 03b8e4da67..0d70e1a78a 100644 --- a/crates/ui-egui/src/canvas/outline.rs +++ b/crates/ui-egui/src/canvas/outline.rs @@ -218,10 +218,13 @@ pub(super) fn hit_at(app: &VectorcraftApp, p: Point, zoom: f64) -> Option Option { - hit_with(app, p, zoom, |doc, p, opt| vectorcraft_doc::hit::hit_test(doc, p, vectorcraft_doc::hit::HitOptions { clip_outlines: true, ..opt })) + hit_with(app, p, zoom, |doc, p, opt| { + vectorcraft_doc::hit::hit_test(doc, p, vectorcraft_doc::hit::HitOptions { clip_outlines: true, unfilled_interiors: true, ..opt }) + }) } /// `test` on the active document at document point `p`, with the options the selection tools hit diff --git a/docs/mcp.md b/docs/mcp.md index 1bbe49574d..2e60f1dd75 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9034,6 +9034,9 @@ The Selection & Anchor Display and General preferences apply to `pointer_gesture handle or segment for Direct Selection, the Anchor Point, Add and Delete Anchor Point and Scissors tools, and the Pen with Alt. A handle shorter than that leaves its anchor to be picked when pressed nearer the anchor. - `objectSelectionByPathOnly`: a click inside a filled path or compound path doesn't select it, one on its path does. + Off (the default), a selection tool click inside the closed subpaths of a path or compound path with no fill selects + it when no other object is hit there, the topmost such path first; guides and clipping paths are still picked by + their path only (#9175). - `ctrlClickSelectsBehind` (on by default): a Selection tool click with `mods: {cmd: true}` (Command on macOS, Ctrl elsewhere) selects the object under the selected one there, the next such click the one under that, then the topmost again. Cmd held to borrow the selection tool from another tool clicks as usual. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index e15f6be884..0d3221a843 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -694,6 +694,8 @@ since 2026-10-01. **Selection fill eligibility (#6625):** Path and compound-path interiors use any enabled non-None fill row (#6625). A lower visible fill remains selectable beneath a top None row in the same object; hidden-only and true-None interiors miss. Zero-opacity fills remain selectable. Original CPU-render and document-hit regressions in `crates/engine/tests/path_fill_hits.rs` cover seven Path and five Compound cases, including stroke edges, geometric outlines, Outline/path-only modes and compound holes. Hidden-fill and no-fill stroked paths must respect butt, round and square caps and bevel, round and miter joins. Focused cap/join CPU regressions passed. Scores and estimates unchanged. +- **Clicks inside unfilled shapes (#9175):** with Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection pick a closed path or compound path with no fill by a click inside its closed subpaths, when no other object is hit there; among such paths the topmost is picked, and Select Behind lists them after the objects that paint there. Open paths, guides and clipping paths are still picked by their path only, and Outline view is unchanged. This is VectorCraft's own rule. Tests: `an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline`, `an_open_path_is_not_hit_inside`, `art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame`, `an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes`, `guides_and_clipping_paths_are_not_hit_inside`, `a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks` and `symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints` in `crates/doc/src/hit/tests.rs`, and `a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only` (MCP). Scores and estimates unchanged. + - **PDF authored replacement text (#6165):** `crates/pdf/src/tests/actual_text.rs` covers replacement once with suffix placement, PDF text-string decoding, empty and nested owners, sibling spans, page reset, multiple text-show operations, style/line changes, fill-and-stroke, reader windows and bounded input. Authored logical-order stretches are protected while adjacent ordinary text still undergoes reconstruction. The replacement takes its first placed glyph's style and line; its characters are not redistributed over later lines/styles. Exact mixed-direction paragraph layout is not claimed. No export changes; scores and hours stay at 75% / 10–20 h. - **PDF stroked type (#7741):** `imported_stroked_type_keeps_the_files_cap_join_and_miter_limit` in `crates/pdf/src/tests/textstroke.rs` covers round, projecting and butt caps, round, bevel and miter joins and a miter limit of 3 on type stroked in rendering modes 1, 2, 5 and 6, shown as a word, a glyph at a time and under `ActualText`; glyphs stroked with another join as runs of their own; and a glyph filled and stroked after one stroked otherwise, which keeps the join of the glyph before it. Synthetic PDFs written in the test (standard Helvetica, not embedded); no fonts or fixtures added. The dash array is not yet carried to the characters. From a335fbbf02b3a68e41bf0ebf81ffeff306f53231 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 18:42:51 -0800 Subject: [PATCH 2/3] Docs: unfilled-interior selection scope and fill eligibility The Path Only preference entry in docs/mcp.md now says the click inside an unfilled closed path does not select it in Outline view. Both docs state the condition as a click that hits no object's fill, stroke or path there, so the topmost of two overlapping unfilled paths is still picked. The #6625 fill eligibility entry now says hidden-only and None interiors are picked with Path Only off when nothing else is hit. --- docs/mcp.md | 3 ++- docs/target-app-parity.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index 2e60f1dd75..e5b9296a0d 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9035,7 +9035,8 @@ The Selection & Anchor Display and General preferences apply to `pointer_gesture Pen with Alt. A handle shorter than that leaves its anchor to be picked when pressed nearer the anchor. - `objectSelectionByPathOnly`: a click inside a filled path or compound path doesn't select it, one on its path does. Off (the default), a selection tool click inside the closed subpaths of a path or compound path with no fill selects - it when no other object is hit there, the topmost such path first; guides and clipping paths are still picked by + it when the click hits no object's fill, stroke or path there, the topmost such path first, except in Outline view; + guides and clipping paths are still picked by their path only (#9175). - `ctrlClickSelectsBehind` (on by default): a Selection tool click with `mods: {cmd: true}` (Command on macOS, Ctrl elsewhere) selects the object under the selected one there, the next such click the one under that, then the diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 0d3221a843..40b24d967d 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -692,9 +692,9 @@ since 2026-10-01. - **Save refusal (#6146):** ordinary File > Save to its own location offers Save As after a terminal permission/read-only refusal, suggesting the original name and format, preserving options for the unchanged format and opening the chosen format’s Save options on a change. Cancel keeps the failed-save state. Busy pickers, recovery-copy errors, other failures, explicit destinations and Close/Quit keep the existing dialog. Engine, UI and MCP regression cases are in `cmd/fileio/tests_readonly.rs`, `io/tests_read_only_save.rs` and MCP `tests/fileio.rs`; focused UI regressions passed; engine regression execution and native panel acceptance pending. Scores and hours unchanged. -**Selection fill eligibility (#6625):** Path and compound-path interiors use any enabled non-None fill row (#6625). A lower visible fill remains selectable beneath a top None row in the same object; hidden-only and true-None interiors miss. Zero-opacity fills remain selectable. Original CPU-render and document-hit regressions in `crates/engine/tests/path_fill_hits.rs` cover seven Path and five Compound cases, including stroke edges, geometric outlines, Outline/path-only modes and compound holes. Hidden-fill and no-fill stroked paths must respect butt, round and square caps and bevel, round and miter joins. Focused cap/join CPU regressions passed. Scores and estimates unchanged. +**Selection fill eligibility (#6625):** Path and compound-path interiors use any enabled non-None fill row (#6625). A lower visible fill remains selectable beneath a top None row in the same object; hidden-only and true-None interiors miss with Object Selection by Path Only on or in Outline view, and with it off are picked only when the click hits nothing else there (#9175, below). Zero-opacity fills remain selectable. Original CPU-render and document-hit regressions in `crates/engine/tests/path_fill_hits.rs` cover seven Path and five Compound cases, including stroke edges, geometric outlines, Outline/path-only modes and compound holes. Hidden-fill and no-fill stroked paths must respect butt, round and square caps and bevel, round and miter joins. Focused cap/join CPU regressions passed. Scores and estimates unchanged. -- **Clicks inside unfilled shapes (#9175):** with Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection pick a closed path or compound path with no fill by a click inside its closed subpaths, when no other object is hit there; among such paths the topmost is picked, and Select Behind lists them after the objects that paint there. Open paths, guides and clipping paths are still picked by their path only, and Outline view is unchanged. This is VectorCraft's own rule. Tests: `an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline`, `an_open_path_is_not_hit_inside`, `art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame`, `an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes`, `guides_and_clipping_paths_are_not_hit_inside`, `a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks` and `symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints` in `crates/doc/src/hit/tests.rs`, and `a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only` (MCP). Scores and estimates unchanged. +- **Clicks inside unfilled shapes (#9175):** with Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection pick a closed path or compound path with no fill by a click inside its closed subpaths, when the click hits no object's fill, stroke or path there; among such paths the topmost is picked, and Select Behind lists them after the objects that paint there. Open paths, guides and clipping paths are still picked by their path only, and Outline view is unchanged. This is VectorCraft's own rule. Tests: `an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline`, `an_open_path_is_not_hit_inside`, `art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame`, `an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes`, `guides_and_clipping_paths_are_not_hit_inside`, `a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks` and `symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints` in `crates/doc/src/hit/tests.rs`, and `a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only` (MCP). Scores and estimates unchanged. - **PDF authored replacement text (#6165):** `crates/pdf/src/tests/actual_text.rs` covers replacement once with suffix placement, PDF text-string decoding, empty and nested owners, sibling spans, page reset, multiple text-show operations, style/line changes, fill-and-stroke, reader windows and bounded input. Authored logical-order stretches are protected while adjacent ordinary text still undergoes reconstruction. The replacement takes its first placed glyph's style and line; its characters are not redistributed over later lines/styles. Exact mixed-direction paragraph layout is not claimed. No export changes; scores and hours stay at 75% / 10–20 h. - **PDF stroked type (#7741):** `imported_stroked_type_keeps_the_files_cap_join_and_miter_limit` in `crates/pdf/src/tests/textstroke.rs` covers round, projecting and butt caps, round, bevel and miter joins and a miter limit of 3 on type stroked in rendering modes 1, 2, 5 and 6, shown as a word, a glyph at a time and under `ActualText`; glyphs stroked with another join as runs of their own; and a glyph filled and stroked after one stroked otherwise, which keeps the join of the glyph before it. Synthetic PDFs written in the test (standard Helvetica, not embedded); no fonts or fixtures added. The dash array is not yet carried to the characters. From 94afe08ebaaeb81aa5fe2046b4acb0fbc00ba573 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 23:26:28 -0800 Subject: [PATCH 3/3] Docs: unfilled-interior selection skips bounds hits and Preview-off layers A symbol instance, text, a blend or an envelope is hit anywhere in its bounds, and that hit keeps a click from reaching an unfilled path below. Art on a layer whose Preview is off is hit in outline, so its unfilled paths are not picked from inside. --- docs/mcp.md | 6 +++--- docs/target-app-parity.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index e5b9296a0d..3df356488c 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9035,9 +9035,9 @@ The Selection & Anchor Display and General preferences apply to `pointer_gesture Pen with Alt. A handle shorter than that leaves its anchor to be picked when pressed nearer the anchor. - `objectSelectionByPathOnly`: a click inside a filled path or compound path doesn't select it, one on its path does. Off (the default), a selection tool click inside the closed subpaths of a path or compound path with no fill selects - it when the click hits no object's fill, stroke or path there, the topmost such path first, except in Outline view; - guides and clipping paths are still picked by - their path only (#9175). + it when the click hits no other object there, by its fill, stroke, path or bounds (a symbol instance, for example, + is hit anywhere in its bounds), the topmost such path first, except in Outline view and on a layer whose Preview is + off; guides and clipping paths are still picked by their path only (#9175). - `ctrlClickSelectsBehind` (on by default): a Selection tool click with `mods: {cmd: true}` (Command on macOS, Ctrl elsewhere) selects the object under the selected one there, the next such click the one under that, then the topmost again. Cmd held to borrow the selection tool from another tool clicks as usual. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 40b24d967d..9181fe2d78 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -694,7 +694,7 @@ since 2026-10-01. **Selection fill eligibility (#6625):** Path and compound-path interiors use any enabled non-None fill row (#6625). A lower visible fill remains selectable beneath a top None row in the same object; hidden-only and true-None interiors miss with Object Selection by Path Only on or in Outline view, and with it off are picked only when the click hits nothing else there (#9175, below). Zero-opacity fills remain selectable. Original CPU-render and document-hit regressions in `crates/engine/tests/path_fill_hits.rs` cover seven Path and five Compound cases, including stroke edges, geometric outlines, Outline/path-only modes and compound holes. Hidden-fill and no-fill stroked paths must respect butt, round and square caps and bevel, round and miter joins. Focused cap/join CPU regressions passed. Scores and estimates unchanged. -- **Clicks inside unfilled shapes (#9175):** with Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection pick a closed path or compound path with no fill by a click inside its closed subpaths, when the click hits no object's fill, stroke or path there; among such paths the topmost is picked, and Select Behind lists them after the objects that paint there. Open paths, guides and clipping paths are still picked by their path only, and Outline view is unchanged. This is VectorCraft's own rule. Tests: `an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline`, `an_open_path_is_not_hit_inside`, `art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame`, `an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes`, `guides_and_clipping_paths_are_not_hit_inside`, `a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks` and `symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints` in `crates/doc/src/hit/tests.rs`, and `a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only` (MCP). Scores and estimates unchanged. +- **Clicks inside unfilled shapes (#9175):** with Object Selection by Path Only off (the default), the Selection, Direct Selection and Group Selection tools, Object Highlighting and a right-click's selection pick a closed path or compound path with no fill by a click inside its closed subpaths, when the click hits no other object there, by its fill, stroke, path or bounds (a symbol instance, for example, is hit anywhere in its bounds); among such paths the topmost is picked, and Select Behind lists them after the objects that paint there. Open paths, guides and clipping paths are still picked by their path only, and Outline view and layers whose Preview is off are unchanged. This is VectorCraft's own rule. Tests: `an_unfilled_closed_path_is_hit_inside_unless_by_path_only_or_in_outline`, `an_open_path_is_not_hit_inside`, `art_inside_an_unfilled_frame_above_it_is_hit_before_the_frame`, `an_unfilled_compound_path_is_hit_inside_its_members_but_not_its_holes`, `guides_and_clipping_paths_are_not_hit_inside`, `a_repeat_is_hit_inside_its_unfilled_copies_but_not_inside_their_masks` and `symbol_art_parts_are_picked_inside_unfilled_frames_after_what_paints` in `crates/doc/src/hit/tests.rs`, and `a_click_inside_an_unfilled_shape_selects_it_unless_by_path_only` (MCP). Scores and estimates unchanged. - **PDF authored replacement text (#6165):** `crates/pdf/src/tests/actual_text.rs` covers replacement once with suffix placement, PDF text-string decoding, empty and nested owners, sibling spans, page reset, multiple text-show operations, style/line changes, fill-and-stroke, reader windows and bounded input. Authored logical-order stretches are protected while adjacent ordinary text still undergoes reconstruction. The replacement takes its first placed glyph's style and line; its characters are not redistributed over later lines/styles. Exact mixed-direction paragraph layout is not claimed. No export changes; scores and hours stay at 75% / 10–20 h. - **PDF stroked type (#7741):** `imported_stroked_type_keeps_the_files_cap_join_and_miter_limit` in `crates/pdf/src/tests/textstroke.rs` covers round, projecting and butt caps, round, bevel and miter joins and a miter limit of 3 on type stroked in rendering modes 1, 2, 5 and 6, shown as a word, a glyph at a time and under `ActualText`; glyphs stroked with another join as runs of their own; and a glyph filled and stroked after one stroked otherwise, which keeps the join of the glyph before it. Synthetic PDFs written in the test (standard Helvetica, not embedded); no fonts or fixtures added. The dash array is not yet carried to the characters.