mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
removed unnecessary update_rows() call and minor refactoring
This commit is contained in:
parent
948e16e3c7
commit
fea917c8f2
@ -67,9 +67,7 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
|
||||
}
|
||||
|
||||
match key.code {
|
||||
KeyCode::Char('q') => {
|
||||
return Ok(());
|
||||
}
|
||||
KeyCode::Char('q') => return Ok(()),
|
||||
KeyCode::Down | KeyCode::Char('j') => list_state.select_next(),
|
||||
KeyCode::Up | KeyCode::Char('k') => list_state.select_previous(),
|
||||
KeyCode::Home | KeyCode::Char('g') => list_state.select_first(),
|
||||
@ -102,7 +100,7 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
KeyCode::Char('s') | KeyCode::Char('/') => {
|
||||
KeyCode::Char('s' | '/') => {
|
||||
list_state.message.push_str("search:|");
|
||||
is_searching = true;
|
||||
}
|
||||
|
@ -374,23 +374,21 @@ impl<'a> ListState<'a> {
|
||||
}
|
||||
})
|
||||
.enumerate()
|
||||
.find_map(|(i, s)| {
|
||||
if s.name.contains(self.search_query.as_str()) {
|
||||
Some(i)
|
||||
.find_map(|(idx, exercise)| {
|
||||
if exercise.name.contains(self.search_query.as_str()) {
|
||||
Some(idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
match idx {
|
||||
Some(i) => {
|
||||
let exercise_ind = i;
|
||||
Some(x) => {
|
||||
let exercise_ind = x;
|
||||
self.scroll_state.set_selected(exercise_ind);
|
||||
self.update_rows();
|
||||
}
|
||||
None => {
|
||||
let msg = String::from("[NOT FOUND]") + &self.message.clone();
|
||||
self.message.clear();
|
||||
let msg = String::from(" (not found)");
|
||||
self.message.push_str(&msg);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user