mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 03:52:45 +01:00
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.
This commit is contained in:
1 parent
e94e82dc8c
commit
552ce4a803
2 files changed
+23
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user