blob: 2137f47d49a4ea34204d9021ca19912f71c88055 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
use super::CommandEntry;
pub struct Selection {
pub current_selected_command_index: Option<usize>,
}
impl Selection {
pub fn new() -> Self {
Self {
current_selected_command_index: None,
}
}
pub fn move_up(&mut self, all_commands: &[CommandEntry]) {
match self.current_selected_command_index.as_mut() {
Some(i) if *i > 0 => {
*i -= 1;
},
None => {
self.current_selected_command_index = Some(all_commands.len().saturating_sub(1));
},
_ => {
self.current_selected_command_index = None;
},
}
}
pub fn move_down(&mut self, all_commands: &[CommandEntry]) {
match self.current_selected_command_index.as_mut() {
Some(i) if *i < all_commands.len().saturating_sub(1) => {
*i += 1;
},
None => {
self.current_selected_command_index = Some(0);
},
_ => {
self.current_selected_command_index = None;
},
}
}
}
impl Default for Selection {
fn default() -> Self {
Self::new()
}
}
|