mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-27 09:19:17 +00:00
Follow the framework's Tab order: tests and a11y.rs
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
//! screen reader reads), and the keyboard navigation mode.
|
||||
//!
|
||||
//! Keyboard navigation: F6 / Shift+F6 move the keyboard between the regions of the window (the
|
||||
//! toolbar, the layers panel, the canvas and the properties panel); Tab / Shift+Tab move between
|
||||
//! the controls of a region (wrapping at its ends); Enter or Space activate the control; the
|
||||
//! arrows move along the toolbar and through the layer rows; a menu or flyout opened from the
|
||||
//! toolbar, the layers panel, the canvas and the properties panel); Tab / Shift+Tab follow the
|
||||
//! framework's one Tab order over every control the window draws, across regions; Enter or Space
|
||||
//! activate the control; the arrows move along the toolbar and through the layer rows; a menu or flyout opened from the
|
||||
//! keyboard takes it, and gives it back to its button when it closes; Escape goes back to the
|
||||
//! canvas, where every shortcut works as usual. A focus ring shows the control with the keyboard
|
||||
//! until the next pointer press.
|
||||
@@ -289,7 +289,7 @@ pub fn keyboard(ctx: &Context) -> bool {
|
||||
// Frame hooks.
|
||||
|
||||
/// Before the panels draw: pointer presses, the focused control's region, and the navigation
|
||||
/// keys (F6, Tab, arrows, Escape), which are taken out of the input when they move the keyboard.
|
||||
/// keys (F6, arrows, Escape), which are taken out of the input when they move the keyboard.
|
||||
pub fn begin(app: &mut FigApp, ctx: &Context, root_scope: Id) {
|
||||
app.ui.nav.last = std::mem::take(&mut app.ui.nav.next);
|
||||
// Before the keys: a panel edge derived from the root scope must already be excluded.
|
||||
@@ -360,28 +360,6 @@ fn keys(app: &mut FigApp, ctx: &Context) {
|
||||
i.events.iter().any(|e| matches!(e, Event::Key { key, pressed: true, modifiers, .. } if *key == k && modifiers.matches_exact(m)))
|
||||
})
|
||||
};
|
||||
// Tab moves between the region's controls (on the canvas it stays the select-next shortcut).
|
||||
// A layer rename takes Tab itself (on to the next row's name).
|
||||
let tab = if pressed(Key::Tab, Modifiers::NONE) {
|
||||
Some(1)
|
||||
} else if pressed(Key::Tab, Modifiers::SHIFT) {
|
||||
Some(-1)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(step) = tab
|
||||
&& app.ui.rename.is_none()
|
||||
{
|
||||
ctx.memory_mut(|m| m.move_focus(FocusDirection::None));
|
||||
if region != Region::Canvas {
|
||||
ctx.input_mut(|i| {
|
||||
i.consume_key(Modifiers::SHIFT, Key::Tab);
|
||||
i.consume_key(Modifiers::NONE, Key::Tab);
|
||||
});
|
||||
app.ui.nav.keyboard = true;
|
||||
step_within(app, ctx, region, step);
|
||||
}
|
||||
}
|
||||
// egui moves the focus with the arrows too; here they belong to fields (steps), the toolbar
|
||||
// and the layer rows.
|
||||
let arrows = [Key::ArrowLeft, Key::ArrowRight, Key::ArrowUp, Key::ArrowDown];
|
||||
@@ -619,7 +597,7 @@ fn focus(app: &mut FigApp, ctx: &Context, id: Id) {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
|
||||
/// Tab / Shift+Tab (and the toolbar's arrows): the next or previous control in the region,
|
||||
/// The toolbar's arrows: the next or previous control in the region,
|
||||
/// wrapping. Going back from a field being edited skips the field it is part of.
|
||||
fn step_within(app: &mut FigApp, ctx: &Context, region: Region, step: i32) {
|
||||
let list = focusables(ctx, &app.ui.nav, region);
|
||||
|
||||
@@ -127,26 +127,24 @@ fn f6_cycles_the_regions_and_lands_on_the_active_tool_and_the_selected_row() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_moves_between_the_properties_controls_and_wraps_without_leaving_the_panel() {
|
||||
fn tab_walks_the_properties_controls_then_leaves_the_panel_in_the_framework_order() {
|
||||
let (mut u, a, _) = setup();
|
||||
f6(&mut u, false);
|
||||
let first = name(&u);
|
||||
let mut seen = vec![first.clone()];
|
||||
assert_eq!(region(&u), Region::Properties);
|
||||
let mut seen = vec![name(&u)];
|
||||
for _ in 0..200 {
|
||||
press(&mut u, Key::Tab, Modifiers::NONE);
|
||||
assert_eq!(region(&u), Region::Properties);
|
||||
if name(&u) == first {
|
||||
if region(&u) != Region::Properties {
|
||||
break;
|
||||
}
|
||||
seen.push(name(&u));
|
||||
let n = name(&u);
|
||||
assert!(!seen.contains(&n), "Tab revisited {n} before leaving the panel: {seen:?}");
|
||||
seen.push(n);
|
||||
}
|
||||
assert_eq!(name(&u), first, "Tab wraps round to the panel's first control");
|
||||
assert_ne!(region(&u), Region::Properties, "Tab after the last Properties control leaves the panel");
|
||||
for want in ["Width", "Height", "Rotation", "Opacity"] {
|
||||
assert!(seen.iter().any(|n| n == want), "{want} not reached by Tab: {seen:?}");
|
||||
}
|
||||
// Shift+Tab steps back.
|
||||
press(&mut u, Key::Tab, Modifiers::SHIFT);
|
||||
assert_eq!(Some(&name(&u)), seen.last());
|
||||
// Tab moved the keyboard, not the selection.
|
||||
assert_eq!(u.app.session.selection(), vec![a]);
|
||||
}
|
||||
@@ -214,18 +212,19 @@ fn escape_returns_to_the_canvas_where_shortcuts_and_tab_work_again() {
|
||||
// Tab on the canvas selects the next layer and keeps the keyboard there.
|
||||
press(&mut u, Key::Tab, Modifiers::NONE);
|
||||
assert_eq!(u.app.session.selection(), vec![b]);
|
||||
assert_eq!(name(&u), "Canvas");
|
||||
assert_eq!((region(&u), name(&u)), (Region::Canvas, "Canvas".to_string()), "Tab on the focused canvas keeps focus there");
|
||||
press(&mut u, Key::R, Modifiers::NONE);
|
||||
assert_eq!(u.app.session.tool.tool, ToolId::Rectangle);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_on_the_canvas_selects_the_next_layer_without_keyboard_mode() {
|
||||
let (mut u, _, b) = setup();
|
||||
fn a_bare_tab_with_nothing_focused_selects_no_layer_and_moves_focus_into_the_window() {
|
||||
let (mut u, a, _) = setup();
|
||||
assert!(u.ctx.memory(|m| m.focused()).is_none());
|
||||
press(&mut u, Key::Tab, Modifiers::NONE);
|
||||
u.frame(vec![]);
|
||||
assert_eq!(u.app.session.selection(), vec![b]);
|
||||
assert!(u.ctx.memory(|m| m.focused()).is_none(), "Tab doesn't wander into the tab bar");
|
||||
assert_eq!(u.app.session.selection(), vec![a], "the selection is unchanged");
|
||||
assert!(u.ctx.memory(|m| m.focused()).is_some(), "Tab focuses a stop in the window");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user