simplify register_movement

This commit is contained in:
Simon Gardling
2022-05-11 15:56:05 -04:00
parent 5af022929c
commit 051197bfe2

View File

@@ -70,8 +70,11 @@ impl<'a> AutoComplete<'a> {
match movement { match movement {
Movement::Up => { Movement::Up => {
// subtract one, if fail, set to maximum index value. // if self.i is below 1, it's at
self.i = self.i.checked_sub(1).unwrap_or(hints.len() - 1); match self.i {
0 => self.i = hints.len() - 1,
_ => self.i -= 1,
}
} }
Movement::Down => { Movement::Down => {
// add one, if resulting value is above maximum i value, set i to 0 // add one, if resulting value is above maximum i value, set i to 0