mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-05 21:28:48 +00:00
Fix selection bug on search
This commit is contained in:
parent
847e09b637
commit
e85cc943b3
28
src/list.rs
28
src/list.rs
|
@ -238,6 +238,13 @@ impl CustomList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resets the selection to the first item
|
||||||
|
pub fn reset_selection(&mut self) {
|
||||||
|
if !self.filtered_items.is_empty() {
|
||||||
|
self.list_state.select(Some(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle key events, we are only interested in `Press` and `Repeat` events
|
/// Handle key events, we are only interested in `Press` and `Repeat` events
|
||||||
pub fn handle_key(&mut self, event: KeyEvent, state: &AppState) -> Option<Command> {
|
pub fn handle_key(&mut self, event: KeyEvent, state: &AppState) -> Option<Command> {
|
||||||
if event.kind == KeyEventKind::Release {
|
if event.kind == KeyEventKind::Release {
|
||||||
|
@ -325,18 +332,15 @@ impl CustomList {
|
||||||
self.filtered_items.len()
|
self.filtered_items.len()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(curr_selection) = self.list_state.selected() {
|
let curr_selection = self.list_state.selected().unwrap();
|
||||||
if self.at_root() {
|
if self.at_root() {
|
||||||
self.list_state
|
self.list_state
|
||||||
.select(Some((curr_selection + 1).min(count - 1)));
|
.select(Some((curr_selection + 1).min(count - 1)));
|
||||||
} else {
|
} else {
|
||||||
// When we are not at the root, we have to account for 1 more "virtual" node, `..`. So
|
// When we are not at the root, we have to account for 1 more "virtual" node, `..`. So
|
||||||
// the count is 1 bigger (select is 0 based, because it's an index)
|
// the count is 1 bigger (select is 0 based, because it's an index)
|
||||||
self.list_state
|
self.list_state
|
||||||
.select(Some((curr_selection + 1).min(count)));
|
.select(Some((curr_selection + 1).min(count)));
|
||||||
}
|
|
||||||
} else if count > 0 {
|
|
||||||
self.list_state.select(Some(0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,10 @@ fn run<B: Backend>(terminal: &mut Terminal<B>, state: &AppState) -> io::Result<(
|
||||||
search_input = String::new();
|
search_input = String::new();
|
||||||
in_search_mode = false
|
in_search_mode = false
|
||||||
}
|
}
|
||||||
KeyCode::Enter => in_search_mode = false,
|
KeyCode::Enter => {
|
||||||
|
in_search_mode = false;
|
||||||
|
custom_list.reset_selection();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else if let Some(cmd) = custom_list.handle_key(key, state) {
|
} else if let Some(cmd) = custom_list.handle_key(key, state) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user