mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
merge-c4: 3.1: a Lasso click deselects only when its operation is New (#13612)
This commit is contained in:
@@ -340,7 +340,8 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> {
|
||||
}
|
||||
|
||||
/// The release closes a freehand outline (`Commit`) unless straight segments are on; a freehand outline of fewer
|
||||
/// than 3 points (a click) is [`SelectEvent::Deselect`]. Ends a selection drag.
|
||||
/// than 3 points (a click) is [`SelectEvent::Deselect`] when its operation is New, and nothing for Add, Subtract
|
||||
/// and Intersect, which keep the selection. Ends a selection drag.
|
||||
fn release(&mut self, pointer: &ToolPointer, cx: &mut ToolContext<'_>) {
|
||||
let (tool, probe) = (&mut *self.tool, self.probe);
|
||||
let Some(place) = Place::of(cx) else { return };
|
||||
@@ -350,7 +351,9 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> {
|
||||
}
|
||||
let event = tool.draft.release(sample(pointer, &place));
|
||||
if event == Some(DraftEvent::Cancelled) {
|
||||
tool.report.push(SelectEvent::Deselect);
|
||||
if tool.operation == SelectionOperation::New {
|
||||
tool.report.push(SelectEvent::Deselect);
|
||||
}
|
||||
return;
|
||||
}
|
||||
apply(event, tool.bar, probe.has_selection(), &mut tool.operation, &mut tool.report);
|
||||
|
||||
@@ -578,7 +578,35 @@ fn lasso_alt_clicks_make_straight_segments_that_retract_and_close() {
|
||||
|
||||
// A plain press inside the selection drags the outline instead of drawing.
|
||||
|
||||
// A press and release that draw fewer than 3 points (a click, or a two-point drag) deselect.
|
||||
// A click outside the selection deselects only when its operation is New: a Shift, Alt or Shift+Alt click, or a plain
|
||||
// click with Add on the bar, keeps the selection (#13612). A drag from the same point still selects.
|
||||
#[trial]
|
||||
fn a_lasso_click_deselects_only_in_new_mode() {
|
||||
let selected = Rect::new(20.0, 20.0, 100.0, 100.0);
|
||||
let shift_alt = Mods { shift: true, alt: true, ..NONE };
|
||||
for (mods, deselects) in [(NONE, true), (Mods::SHIFT, false), (Mods::ALT, false), (shift_alt, false)] {
|
||||
let mut rig = rig("Lasso", LassoTool::new(), Fake::selected(selected));
|
||||
click(&mut rig, (200.0, 150.0), mods);
|
||||
let expected = if deselects { vec![SelectEvent::Deselect] } else { Vec::new() };
|
||||
assert_eq!(rig.tool_mut().events(), expected, "a click with {mods:?}");
|
||||
}
|
||||
|
||||
let mut rig = rig("Lasso", LassoTool::new(), Fake::selected(selected));
|
||||
rig.tool_mut().tool().operation(SelectionOperation::Add);
|
||||
click(&mut rig, (200.0, 150.0), NONE);
|
||||
assert!(rig.tool_mut().events().is_empty(), "a plain click with Add on the bar keeps the selection");
|
||||
|
||||
let mut rig = rig("Lasso", LassoTool::new(), Fake::selected(selected));
|
||||
down(&mut rig, (200.0, 150.0), NONE);
|
||||
for point in [(260.0, 150.0), (260.0, 200.0), (230.0, 220.0)] {
|
||||
drag_to(&mut rig, point, NONE);
|
||||
}
|
||||
up(&mut rig, (200.0, 200.0), NONE);
|
||||
assert!(
|
||||
matches!(rig.tool_mut().events().as_slice(), [SelectEvent::Commit { operation: SelectionOperation::New, .. }]),
|
||||
"a drag from outside the selection still selects"
|
||||
);
|
||||
}
|
||||
|
||||
// ---- the Polygonal Lasso ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user