mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03: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 {
|
match key.code {
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => return Ok(()),
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
KeyCode::Down | KeyCode::Char('j') => list_state.select_next(),
|
KeyCode::Down | KeyCode::Char('j') => list_state.select_next(),
|
||||||
KeyCode::Up | KeyCode::Char('k') => list_state.select_previous(),
|
KeyCode::Up | KeyCode::Char('k') => list_state.select_previous(),
|
||||||
KeyCode::Home | KeyCode::Char('g') => list_state.select_first(),
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('s') | KeyCode::Char('/') => {
|
KeyCode::Char('s' | '/') => {
|
||||||
list_state.message.push_str("search:|");
|
list_state.message.push_str("search:|");
|
||||||
is_searching = true;
|
is_searching = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,23 +374,21 @@ impl<'a> ListState<'a> {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find_map(|(i, s)| {
|
.find_map(|(idx, exercise)| {
|
||||||
if s.name.contains(self.search_query.as_str()) {
|
if exercise.name.contains(self.search_query.as_str()) {
|
||||||
Some(i)
|
Some(idx)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
match idx {
|
match idx {
|
||||||
Some(i) => {
|
Some(x) => {
|
||||||
let exercise_ind = i;
|
let exercise_ind = x;
|
||||||
self.scroll_state.set_selected(exercise_ind);
|
self.scroll_state.set_selected(exercise_ind);
|
||||||
self.update_rows();
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let msg = String::from("[NOT FOUND]") + &self.message.clone();
|
let msg = String::from(" (not found)");
|
||||||
self.message.clear();
|
|
||||||
self.message.push_str(&msg);
|
self.message.push_str(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue