Image Trace: switching tools during a divider drag puts the view back

Switching away from the Selection tool while dragging the Split view's
divider left the drag's interaction open with its preview in the
document. The Selection tool now cancels the drag on deactivate, as
Escape does, as it already did for the corner, pie, side and blend
widgets.
This commit is contained in:
dotCooCoo
2026-11-18 16:09:36 -08:00
parent f4071dd56a
commit e9650d17a4
2 changed files with 24 additions and 0 deletions
+1
View File
@@ -915,6 +915,7 @@ impl Tool for SelectionTool {
State::Corner(c) if c.adjusting() => vec![Action::Cancel],
State::Pie(d) if d.adjusting() => vec![Action::Cancel],
State::Sides(d) => d.cancel(),
State::TraceSplit(d) => d.cancel(),
State::BlendWidget(_) | State::Corner(_) | State::Pie(_) => vec![],
other => {
self.state = other;
+23
View File
@@ -234,4 +234,27 @@ mod tests {
assert!(matches!(drag.cancel()[..], [Action::Cancel]));
}
}
/// Switching away from the Selection tool during a divider drag cancels it, as Escape does:
/// the view goes back. After a press that has not moved there is nothing to put back.
#[test]
fn a_tool_switch_cancels_a_divider_drag() {
use crate::{PointerEvent, PointerKind, Tool};
let paint = paint();
let mut selection = Selection::default();
let (doc, id) = traced(Affine::translate((10.0, 20.0)), "split", 0.5);
selection.set([id]);
let c = cx(&doc, &selection, &paint);
let mut t = crate::select::SelectionTool::default();
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Down, 60.0, 40.0)).is_empty());
let a = t.pointer(&c, &PointerEvent::new(PointerKind::Drag, 85.0, 40.0));
assert!(matches!(a.first(), Some(Action::Begin(_))), "{a:?}");
assert_eq!(t.deactivate(&c), vec![Action::Cancel]);
assert!(!t.busy() && !t.transforming());
assert!(t.pointer(&c, &PointerEvent::new(PointerKind::Up, 85.0, 40.0)).is_empty());
t.pointer(&c, &PointerEvent::new(PointerKind::Down, 60.0, 40.0));
assert!(t.busy());
assert!(t.deactivate(&c).is_empty());
assert!(!t.busy());
}
}