diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 8ea9654003..af61045261 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -115,6 +115,7 @@ impl VectorcraftApp { grab: None, carry_target: None, last_drag: None, + escaped_press: false, panes: Default::default(), windows: crate::doc_windows::Windows::new(known), images_with_other_art: None, diff --git a/crates/ui-egui/src/caches.rs b/crates/ui-egui/src/caches.rs index dc2b2b8fc8..23d8dde0f0 100644 --- a/crates/ui-egui/src/caches.rs +++ b/crates/ui-egui/src/caches.rs @@ -96,6 +96,9 @@ pub struct CanvasCache { /// The last drag the tool was sent and the screen point it was at: when the view scrolls under the held /// pointer, the drag goes on at that point in the scrolled view. pub last_drag: Option<(egui::Pos2, vectorcraft_tools::PointerEvent)>, + /// Escape cancelled the tool's press while the button is still down: its release still sends the tool its Up, + /// which gives back a selection tool Cmd lent. + pub escaped_press: bool, /// Window › Arrange › Tile: the renders the panes of the other documents draw. pub panes: canvas::Panes, /// Window › Arrange › Float in Window: what the floating document windows keep between frames. diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index fb6d9f7d1a..99350fa38f 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -361,6 +361,7 @@ impl CanvasTool for SessionTool<'_> { let (left, right, c) = (claim(&mut app, EngineKey::BracketLeft), claim(&mut app, EngineKey::BracketRight), claim(&mut app, EngineKey::Letter('c'))); // shortcut: the sets are the combinations the tools have; a tool with another mix needs its own slice. + app.canvas.escaped_press = true; let keys = match (left, right, curly, c) { (true, true, true, _) => BRACKETS_CURLY, (true, true, false, true) => BRACKETS_C, @@ -539,6 +540,15 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too // The press phase says whether the canvas has the pointer: a dialog, floating panel or menu over it hides the // document point, and a drag that began on the canvas keeps its own phase over them. app.hover_doc = match (pass.press.phase, view) { + // The framework ends a press at Escape; the engine's tool still takes the release that ends it. + if app.canvas.escaped_press && !ui.input(|i| i.pointer.primary_down()) { + app.canvas.escaped_press = false; + dispatch( + app, + &PointerEvent { kind: PointerKind::Up, pos: Point::ZERO, mods: Mods::default(), backquote: false, pressure: 1.0, pen: None }, + view_info, + ); + } (PressPhase::Idle, _) | (_, None) => None, (_, Some(view)) => ui.input(|i| i.pointer.hover_pos()).map(|p| view.to_doc(p)), };