diff --git a/crates/behavior/src/geometry/draft.rs b/crates/behavior/src/geometry/draft.rs index 9c1525a2c..2ae27a6bf 100644 --- a/crates/behavior/src/geometry/draft.rs +++ b/crates/behavior/src/geometry/draft.rs @@ -288,12 +288,17 @@ impl OutlineDraft { /// Where a freehand point of `at` goes. With ⇧ held a [`locking_shift_drags`](Self::locking_shift_drags) Mixed draft's drag follows one line: once the pointer has /// travelled [`LOCK_DISTANCE`] screen points from the last vertex, the nearest of eight directions from there /// is locked and every later point is the pointer's projection onto it, however the pointer wanders, until ⇧ is - /// released. Before the lock the point stays at the vertex. Otherwise [`shift_step`](Self::shift_step). + /// released. Before the lock the point stays at the vertex. A Mixed draft that doesn't lock keeps the pointer's path + /// under ⇧. Otherwise [`shift_step`](Self::shift_step). fn drag_step(&mut self, at: DraftPoint) -> Point { - if !self.locks_shift_drag || self.kind != DraftKind::Mixed || !at.mods.shift || self.polygonal { + if self.kind != DraftKind::Mixed || !at.mods.shift || self.polygonal { self.lock = None; return self.shift_step(at); } + if !self.locks_shift_drag { + self.lock = None; + return at.at; + } let Some(&last) = self.points.last() else { return at.at }; let (origin, direction) = match self.lock { Some(lock) => lock, diff --git a/crates/behavior/tests/geometry/draft.rs b/crates/behavior/tests/geometry/draft.rs index 2aec75ab6..6a0857cc2 100644 --- a/crates/behavior/tests/geometry/draft.rs +++ b/crates/behavior/tests/geometry/draft.rs @@ -82,6 +82,14 @@ fn shift_holds_a_freehand_drag_to_one_line() { assert!(points.len() >= 3, "{points:?}"); assert!(points.iter().all(|p| p.y == 60.0), "the drag stays on the horizontal line through its start: {points:?}"); assert_eq!(points.last().map(|p| p.x), Some(100.0), "and follows the pointer along it"); + + // A selection Lasso's ⇧ at the press adds to the selection: its drag keeps the pointer's path. + let mut lasso = OutlineDraft::new(DraftKind::Mixed, REACH); + lasso.press(at(10.0, 60.0, 1.0), true); + for (x, y) in [(30.0, 63.0), (50.0, 55.0)] { + lasso.drag(shift(x, y)); + } + assert_eq!(lasso.points().last(), Some(&Point::new(50.0, 55.0))); } #[test] diff --git a/crates/draw/src/ui/pen/anchor_tool.rs b/crates/draw/src/ui/pen/anchor_tool.rs index cf5869631..e36351012 100644 --- a/crates/draw/src/ui/pen/anchor_tool.rs +++ b/crates/draw/src/ui/pen/anchor_tool.rs @@ -47,7 +47,7 @@ impl<'a> AnchorTool<'a> { } /// The cursor of `tool` off the overlay's parts with `mods` held; `precise` is the canvas's precise cursor. -fn cursor_of(tool: PathTool, mods: Mods, precise: bool) -> PaintedCursor { +pub(super) fn cursor_of(tool: PathTool, mods: Mods, precise: bool) -> PaintedCursor { // The pen's tip is the bottom left corner of the icon's box. let pen = |badge| PaintedCursor::tool(ToolIcon::Pen.icon(), Vec2::Y * ICON_BOX, Some(badge)); match tool { diff --git a/crates/draw/src/ui/pen/bezier/mod.rs b/crates/draw/src/ui/pen/bezier/mod.rs index ccb906b27..a9c5bff6f 100644 --- a/crates/draw/src/ui/pen/bezier/mod.rs +++ b/crates/draw/src/ui/pen/bezier/mod.rs @@ -14,7 +14,7 @@ mod words; use craft_behavior::geometry::{SelectionOperation, axis_or_diagonal}; use craft_behavior::kurbo::{Point, Rect as DocRect, Vec2}; use craft_behavior::{ - Axis, CanvasView, CursorPriority, EditCommand, GesturePhase, Granularity, HitLevel, HitPriority, HitShape, Intent, MoveMods, NavMove, NavShape, + Axis, CanvasView, Cursor, CursorPriority, EditCommand, GesturePhase, Granularity, HitLevel, HitPriority, HitShape, Intent, MoveMods, NavMove, NavShape, PartKey, PartRef, PointerButton, PressPhase, PressStart, Roving, Sense, }; use craft_keymap::{Chord, Key, Mods}; @@ -41,7 +41,8 @@ pub use model::{AnchorDelete, EditPath, EditSubpath, HandleSide, Knot, KnotRef, pub use style::BezierStyle; pub use words::BezierWords; -use super::PathOptionsSettings; +use super::anchor_tool::cursor_of; +use super::{PathOptionsSettings, PathTool}; /// Insert on a picked anchor adds one halfway along the segment leaving it. const INSERT: Chord = Chord::plain(Key::Insert); @@ -831,9 +832,16 @@ impl<'a> BezierOverlay<'a> { } if matches!(self.tool, BezierTool::AddAnchor | BezierTool::DeleteAnchor) && let Some(result) = cx.part_if_declared(EMPTY) - && matches!(result.press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { - self.report.pressed_empty = true; + let (press, hover) = (result.press, result.hover_pos); + // The part covers the canvas background, so it owns the cursor the host tool shows off the paths too. + if hover.is_some() { + let tool = if self.tool == BezierTool::AddAnchor { PathTool::AddAnchor } else { PathTool::DeleteAnchor }; + cx.cursor(Cursor::Painted(cursor_of(tool, press.mods, space.precise())), CursorPriority::Part); + } + if matches!(press.phase, PressPhase::Down { start, .. } if start.button == PointerButton::Primary) { + self.report.pressed_empty = true; + } } // A press none of the parts carries any more (its part went with the paths) is over for the overlay. if !pressed && cx.press_slot::().is_some() {