From 2d0389c8fdf0042820ba5d4483555e81dcb83e4c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 14:44:44 -0800 Subject: [PATCH] Gradient: moving out of a freeform object ends the Lines mode line In freeform Lines mode, moving the pointer out of the object and back now ends the line being drawn, so the next click on the object starts a new line. The help page describes this way of starting another line in the same object: https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=262 The line ends on the first pointer move, with no button held, that leaves the object. The object counts as its path's area inside any clipping masks above it, plus its own painted art (stroke, glyphs); other art lying over it does not end the line, and outline view, a layer with Preview off and the path-only selection preferences do not shrink the area. Escape and a click off the art still end the line. --- crates/tools/src/xform/freeform.rs | 160 +++++++++++++++++++++++++++-- docs/target-app-parity.md | 1 + 2 files changed, 154 insertions(+), 7 deletions(-) diff --git a/crates/tools/src/xform/freeform.rs b/crates/tools/src/xform/freeform.rs index 89c6faa933..8a5a461a2b 100644 --- a/crates/tools/src/xform/freeform.rs +++ b/crates/tools/src/xform/freeform.rs @@ -8,14 +8,15 @@ //! //! Points mode (the Gradient panel's Draw toggle): a click inside the selected art adds a point //! there, coloured as the gradient is there. Lines mode: successive clicks draw a smooth line -//! through the points they add, until Escape (or a click off the art) ends it; clicking an -//! existing point first starts the line from it. Delete or Backspace removes the selected point. +//! through the points they add, until Escape, a click off the art or moving the pointer out of +//! the object ends it; clicking an existing point first starts the line from it. Delete or +//! Backspace removes the selected point. use serde_json::{Value, json}; use vectorcraft_color::freeform::LineHit; use vectorcraft_color::{Color, Freeform, FreeformMode, FreeformPoint}; use vectorcraft_doc::NodeId; -use vectorcraft_doc::hit::hit_test; +use vectorcraft_doc::hit::{HitOptions, hit_test, hit_test_visible_skipping}; use vectorcraft_geom::{Point, Shape, Vec2}; use super::paint_owner; @@ -183,6 +184,43 @@ fn on_art(cx: &ToolContext, p: Point) -> bool { hit_test(cx.doc, p, cx.hit_options()).is_some_and(|h| cx.selection.objects.contains(&paint_owner(cx.doc, h.leaf))) } +/// Is `p` on object `id`: inside its path's area (where a dragged point stays) and every clipping +/// mask above it, or on its own art where a click hits it with the art lying over it left out (a +/// stroke, type's glyphs)? +fn on_object(cx: &ToolContext, id: NodeId, p: Point) -> bool { + let Some(n) = cx.doc.node(id) else { return false }; + let ancestry = cx.doc.ancestry(id).unwrap_or_default(); + let contains = |shapes: &[(vectorcraft_geom::BezPath, vectorcraft_geom::FillRule)]| { + shapes.iter().any(|(bp, rule)| vectorcraft_geom::hit::fill_contains(bp, *rule, p)) + }; + // A mask with a live effect clips by the effect's result, which the hit test below measures. + let plain = |clip: &vectorcraft_doc::Node| { + let mut effects = false; + clip.walk(&mut |c| { + effects |= c.appearance.effects.iter().any(|e| e.visible) || c.appearance.items.iter().any(|i| i.effects().iter().any(|e| e.visible)); + }); + !effects + }; + let unmasked = || { + ancestry.iter().filter_map(|a| cx.doc.node(*a)).filter(|a| a.clips()).all(|a| { + a.children() + .and_then(|c| c.first()) + .is_none_or(|clip| clip.id == id || plain(clip) && contains(&vectorcraft_doc::hit::clip_regions(clip))) + }) + }; + if contains(&n.clip_shapes(None)) && unmasked() { + return true; + } + let mut keep = std::collections::HashSet::new(); + n.walk(&mut |c| { + keep.insert(c.id); + }); + keep.extend(ancestry); + // The art as painted, whatever the view and the path-only selection preferences. + let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ..cx.hit_options() }; + hit_test_visible_skipping(cx.doc, p, opt, &|n| !keep.contains(&n)).is_some_and(|h| h.leaf == id || h.ancestry.contains(&id)) +} + pub(super) fn press(cx: &ToolContext, a: &Annotator, p: Point) -> (Vec, Gesture) { let mut out = vec![]; let grab = if let Some(i) = a.point_at(cx, p) { @@ -293,8 +331,13 @@ pub(super) fn double_click(cx: &ToolContext, a: &Annotator, p: Point) -> Vec