diff --git a/crates/tools/src/select.rs b/crates/tools/src/select.rs index 851e28664a..34b08bd2c0 100644 --- a/crates/tools/src/select.rs +++ b/crates/tools/src/select.rs @@ -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; diff --git a/crates/tools/src/trace_split.rs b/crates/tools/src/trace_split.rs index 1cb7018c99..6ec3509789 100644 --- a/crates/tools/src/trace_split.rs +++ b/crates/tools/src/trace_split.rs @@ -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()); + } }