diff --git a/crates/ui-egui/src/pen_mode_tests.rs b/crates/ui-egui/src/pen_mode_tests.rs index 6fa54959d..31af1c663 100644 --- a/crates/ui-egui/src/pen_mode_tests.rs +++ b/crates/ui-egui/src/pen_mode_tests.rs @@ -92,3 +92,19 @@ fn the_mode_switcher_ends_the_pen_path_too() { assert_eq!(layers(&u), finished, "{label}: the path is kept as Escape keeps it"); } } + +#[test] +fn a_press_on_the_mode_switcher_does_not_reach_the_canvas() { + // The switcher floats over the canvas: the pen must not place an anchor under it. + for label in ["Prototype", "Design"] { + let mut u = Ui::new(Session::new()); + u.app.run("tool.set", json!({"tool": "pen"})); + let at = mode_button(&mut u, label); + u.button(at, true); + assert!(u.app.session.tool.pen.is_none(), "{label}: the press starts no path"); + u.button(at, false); + u.frame(vec![]); + assert!(u.app.session.tool.pen.is_none(), "{label}: no path after the click"); + assert_eq!(layers(&u), 0, "{label}: the click adds nothing"); + } +} diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index 24af4a640..3e4a224e1 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -329,6 +329,10 @@ fn builder_toolbar(app: &mut FigApp, ui: &mut Ui) { /// toolbar region keyboard navigation moves through. fn pill(ui: &Ui, nav: &mut Nav, canvas: Rect, width: f32, t: &Tokens) -> Rect { let rect = Rect::from_center_size(pos2(canvas.center().x, canvas.max.y - 12.0 - 24.0), vec2(width, 48.0)); + // The pill takes the press and the drag over it: its buttons sense clicks only, and egui gives + // a drag the canvas under them would sense to the canvas, so the pen placed an anchor there. + // Not focusable: the keyboard walks the buttons, not the pill. + ui.interact(rect, ui.id().with("pill"), Sense::CLICK | Sense::DRAG); a11y::area(nav, Region::Toolbar, rect); a11y::container_bounds(ui, rect); let painter = ui.painter();