From 759abc01abef8db2ddb27438d2aa179515a762b4 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:04:56 +0000 Subject: [PATCH] The Magnetic Lasso closes within 8 screen points of its first point, so a click where the outline began closes it --- crates/imaging/src/ui/select/magnetic.rs | 16 ++++++++++------ crates/imaging/tests/it/select.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/imaging/src/ui/select/magnetic.rs b/crates/imaging/src/ui/select/magnetic.rs index bad19bebe..bd0c7e1be 100644 --- a/crates/imaging/src/ui/select/magnetic.rs +++ b/crates/imaging/src/ui/select/magnetic.rs @@ -9,7 +9,7 @@ use egui::{CornerRadius, Pos2, Rect as ScreenRect, Vec2}; use kurbo::Point; use serde::{Deserialize, Serialize}; -use super::lasso::{DraftKey, draft_command, outline_access, reach}; +use super::lasso::{DraftKey, draft_command, outline_access}; use super::{Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectionProbe, SelectionShape}; /// Where the magnetic lasso cursor's icon touches the document: the icon's own origin. @@ -521,7 +521,7 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { }); return ToolAction::Claimed; }; - if pointer.clicks >= 2 || o.near_start(p, close_radius(cx, &place)) { + if pointer.clicks >= 2 || o.near_start(p, close_radius(&place)) { tool.close(pointer.mods.alt); return ToolAction::Claimed; } @@ -635,7 +635,7 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { draw.stroke(&square, StrokeWidth::Thin, style.color(overlay.handle_stroke)); } if let Some(pointer) = cx.pointer - && o.near_start(place.doc(pointer.pos), close_radius(cx, &place)) + && o.near_start(place.doc(pointer.pos), close_radius(&place)) { // The closing cursor: a small circle beside the pointer. let ring = PaintShape::Circle(pointer.pos + side, tokens.shape.radius.sm); @@ -656,7 +656,11 @@ impl CanvasTool for SelectToolPass<'_, MagneticLassoTool> { } } -/// How near the first point a press closes the outline, in document units. -fn close_radius(cx: &ToolContext<'_>, place: &Place) -> f64 { - reach(cx).close / place.zoom().max(0.01) +/// How near the first point a press closes the outline, in screen points. Wider than the slop: the first point snaps +/// to the edge, a few points from the press that placed it, and a press back where the outline began closes it. +const CLOSE_REACH: f64 = 8.0; + +/// [`CLOSE_REACH`] in document units. +fn close_radius(place: &Place) -> f64 { + CLOSE_REACH / place.zoom().max(0.01) } diff --git a/crates/imaging/tests/it/select.rs b/crates/imaging/tests/it/select.rs index 31372842a..5b662dc61 100644 --- a/crates/imaging/tests/it/select.rs +++ b/crates/imaging/tests/it/select.rs @@ -891,6 +891,20 @@ fn magnetic_closes_by_start_click_double_click_or_enter_and_retracts_to_the_firs assert!(rig.tool_mut().events().is_empty(), "retracting commits nothing"); } +// The first point snaps to the edge a few points from the press that placed it, farther than the slop: a click back +// where the outline began closes it, as a click on the start itself does. +#[trial] +fn a_click_where_the_magnetic_outline_began_closes_it() { + let (mut rig, _) = magnetic(); + let began = CENTRE + circle_offset(0.0) * ((RADIUS + 5.0) / RADIUS); + click(&mut rig, pt(began), NONE); + glide_along(&mut rig, 0.0, std::f64::consts::TAU); + rig.fixture().advance(1.0); + click(&mut rig, pt(began), NONE); + let points = committed_polygon(&rig.tool_mut().events()); + assert!(points.len() >= 3 && points.iter().all(|&p| on_circle(p)), "a click where the outline began closes: {points:?}"); +} + // `[` and `]` change the width by 1 within 1..=256 while an outline is open. // With `pressure_width` on, a pen sample at pressure 0.5 halves the searched width (minus one); a mouse sample never