mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-25 04:49:44 +00:00
Fix crash when trying to scroll on empty results
This commit is contained in:
parent
e85cc943b3
commit
b7c2ecedd9
12
src/list.rs
12
src/list.rs
|
@ -242,6 +242,8 @@ impl CustomList {
|
|||
pub fn reset_selection(&mut self) {
|
||||
if !self.filtered_items.is_empty() {
|
||||
self.list_state.select(Some(0));
|
||||
} else {
|
||||
self.list_state.select(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,8 +319,11 @@ impl CustomList {
|
|||
}
|
||||
|
||||
fn try_scroll_up(&mut self) {
|
||||
self.list_state
|
||||
.select(Some(self.list_state.selected().unwrap().saturating_sub(1)));
|
||||
if let Some(selected) = self.list_state.selected() {
|
||||
if selected > 0 {
|
||||
self.list_state.select(Some(selected.saturating_sub(1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn try_scroll_down(&mut self) {
|
||||
|
@ -332,7 +337,7 @@ impl CustomList {
|
|||
self.filtered_items.len()
|
||||
};
|
||||
|
||||
let curr_selection = self.list_state.selected().unwrap();
|
||||
if let Some(curr_selection) = self.list_state.selected() {
|
||||
if self.at_root() {
|
||||
self.list_state
|
||||
.select(Some((curr_selection + 1).min(count - 1)));
|
||||
|
@ -343,6 +348,7 @@ impl CustomList {
|
|||
.select(Some((curr_selection + 1).min(count)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Scroll the preview window down
|
||||
fn scroll_preview_window_down(&mut self) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user