1use crate::{Direction, KeyboardInput};
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub enum GridCommand {
5 Left,
6 Right,
7 Up,
8 Down,
9 FirstInRow,
10 LastInRow,
11 PreviousPage,
12 NextPage,
13 PreviousLargePage,
15 NextLargePage,
17}
18impl GridCommand {
19 pub fn key(direction: Direction, input: KeyboardInput<'_>) -> Option<Self> {
20 if input.composing || input.editable || input.control || input.meta || input.alt {
21 return None;
22 }
23 match (input.key, input.shift) {
24 ("PageUp", true) => Some(Self::PreviousLargePage),
25 ("PageDown", true) => Some(Self::NextLargePage),
26 (_, true) => None,
27 ("ArrowLeft", false) => Some(if direction == Direction::Rtl {
28 Self::Right
29 } else {
30 Self::Left
31 }),
32 ("ArrowRight", false) => Some(if direction == Direction::Rtl {
33 Self::Left
34 } else {
35 Self::Right
36 }),
37 ("ArrowUp", false) => Some(Self::Up),
38 ("ArrowDown", false) => Some(Self::Down),
39 ("Home", false) => Some(Self::FirstInRow),
40 ("End", false) => Some(Self::LastInRow),
41 ("PageUp", false) => Some(Self::PreviousPage),
42 ("PageDown", false) => Some(Self::NextPage),
43 _ => None,
44 }
45 }
46}