From 552ce4a80302d244944cd5edede1bfa15263e7f3 Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 20 Nov 2026 19:58:58 +0100 Subject: [PATCH] Canvas scroll bar arrows take no keyboard focus The document chrome's step arrows were focusable stops. Tab stopped on them, and when the canvas's focused part went away (a crop that shrank the document) focus fell through to an arrow, which then took the Escape that cancels the next crop frame. The canvas scrolls with its own keys (arrows, Page Up/Down, Home and End), and in the reference application the scroll bar arrows take no keyboard focus, so the arrows are pointer-only, like the corner. --- crates/ui-canvas/src/canvas/scrollbars/mod.rs | 5 ++++- .../ui-canvas/tests/it/canvas/scrollbars.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/ui-canvas/src/canvas/scrollbars/mod.rs b/crates/ui-canvas/src/canvas/scrollbars/mod.rs index 6c2bb011c..710e39816 100644 --- a/crates/ui-canvas/src/canvas/scrollbars/mod.rs +++ b/crates/ui-canvas/src/canvas/scrollbars/mod.rs @@ -390,7 +390,10 @@ impl Component for CanvasScrollbars<'_> { for (key, axis, bar) in bars.each() { cx.scroll(key, bar.track, axis, bar.span.clone()); for (part, rect, _) in bar.arrows(key, axis) { - cx.part(part, rect).sense(Sense::CLICK | Sense::FOCUS).focusable(); + // As in the reference application the step arrows take no keyboard focus: the canvas scrolls with its own + // keys (the arrows, Page Up/Down, Home and End), and a focused arrow would take the Escape that ends a + // tool's edit on the canvas. + cx.part(part, rect).sense(Sense::CLICK).pointer_only("the canvas scrolls with its own keys"); } } if let Some(corner) = bars.corner { diff --git a/crates/ui-canvas/tests/it/canvas/scrollbars.rs b/crates/ui-canvas/tests/it/canvas/scrollbars.rs index a7b6e1d68..bbecbcc7d 100644 --- a/crates/ui-canvas/tests/it/canvas/scrollbars.rs +++ b/crates/ui-canvas/tests/it/canvas/scrollbars.rs @@ -272,3 +272,22 @@ fn a_dragged_vertical_thumb_shows_the_tip_beside_it_and_nothing_when_it_is_not_d assert_eq!(fixture.texts().len(), at_rest, "bars with no tip show none"); assert_eq!(shows_tip(&fixture), None); } + +/// The step arrows scroll under the pointer but take no keyboard focus: Tab never stops on them, so the canvas keeps +/// its own keys and an Escape reaches what the canvas shows (a tool's edit), as in the reference application. +#[trial] +fn the_document_scroll_arrows_take_no_keyboard_focus() { + let (mut fixture, view, _) = document_scrollbars(); + let start = view.get().center; + let arrow = fixture.by_label("Scroll right").expect("the right arrow").center(); + fixture.frame(vec![pointer::moved(arrow)]).frame(vec![pointer::press(arrow)]).frame(vec![pointer::release(arrow)]); + assert!(view.get().center.x > start.x, "the arrow still steps"); + for step in 0..8 { + fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle(); + let on_arrow = fixture + .focused_stop() + .and_then(|(_, part)| part) + .is_some_and(|part| matches!(format!("{:?}", part.key).as_str(), "PartKey(\"vertical\")" | "PartKey(\"horizontal\")")); + assert!(!on_arrow, "Tab {step} stopped on a scroll bar part: {:?}", fixture.focused_stop()); + } +}