ui: Wrap around list when at the endoflife

Pressing "up"/"k" at the top of the UI will now go to the end of the list. And
same in reverse.
This commit is contained in:
Brandon W Maister 2023-02-18 11:27:58 -08:00
parent 85dc2f0707
commit 3060032a95

View file

@ -387,7 +387,7 @@ impl UI {
let index = match self.selection.selected() {
Some(i) => {
if i == 0 {
0
self.ports.len() - 1
} else {
i - 1
}
@ -400,8 +400,12 @@ impl UI {
| KeyEvent { code: KeyCode::Char('j'), .. } => {
let index = match self.selection.selected() {
Some(i) => {
assert!(self.ports.len() > 0, "We must have ports because we have a selection.");
(i + 1).min(self.ports.len() - 1)
let max = self.ports.len() - 1;
if i >= max {
0
} else {
i + 1
}
}
None => 0,
};