move_up will select last item, when no item selected (#907)

pull/912/head
CossonLeo 3 years ago committed by GitHub
parent bca98b5bed
commit b142fd4080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -98,7 +98,8 @@ impl<T: Item> Menu<T> {
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
let len = self.matches.len(); let len = self.matches.len();
let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len; let max_index = len.saturating_sub(1);
let pos = self.cursor.map_or(max_index, |i| (i + max_index) % len) % len;
self.cursor = Some(pos); self.cursor = Some(pos);
self.adjust_scroll(); self.adjust_scroll();
} }

Loading…
Cancel
Save