From 3060032a958f7c787111b06b056a03137c8f26d7 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Sat, 18 Feb 2023 11:27:58 -0800 Subject: [PATCH] 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. --- src/client/ui.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/client/ui.rs b/src/client/ui.rs index 8957ad0..610baff 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -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, };