mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-18 06:58:10 -05:00
Don't exit the list on "to current" if nothing is selected
This commit is contained in:
parent
570bc9f32d
commit
4e12725616
2 changed files with 14 additions and 10 deletions
|
@ -63,7 +63,9 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
|
||||||
list_state.reset_selected()?;
|
list_state.reset_selected()?;
|
||||||
}
|
}
|
||||||
KeyCode::Char('c') => {
|
KeyCode::Char('c') => {
|
||||||
return list_state.selected_to_current_exercise();
|
if list_state.selected_to_current_exercise()? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Redraw to remove the message.
|
// Redraw to remove the message.
|
||||||
KeyCode::Esc => (),
|
KeyCode::Esc => (),
|
||||||
|
|
|
@ -250,25 +250,27 @@ impl<'a> ListState<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected_to_current_exercise(&mut self) -> Result<()> {
|
// Return `true` if there was something to select.
|
||||||
|
pub fn selected_to_current_exercise(&mut self) -> Result<bool> {
|
||||||
let Some(selected) = self.selected else {
|
let Some(selected) = self.selected else {
|
||||||
// TODO: Don't exit list
|
self.message.push_str("Nothing selected to continue at!");
|
||||||
return Ok(());
|
return Ok(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
let ind = self
|
let (ind, _) = self
|
||||||
.app_state
|
.app_state
|
||||||
.exercises()
|
.exercises()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(ind, exercise)| match self.filter {
|
.filter(|(_, exercise)| match self.filter {
|
||||||
Filter::Done => exercise.done.then_some(ind),
|
Filter::Done => exercise.done,
|
||||||
Filter::Pending => (!exercise.done).then_some(ind),
|
Filter::Pending => !exercise.done,
|
||||||
Filter::None => Some(ind),
|
Filter::None => true,
|
||||||
})
|
})
|
||||||
.nth(selected)
|
.nth(selected)
|
||||||
.context("Invalid selection index")?;
|
.context("Invalid selection index")?;
|
||||||
|
|
||||||
self.app_state.set_current_exercise_ind(ind)
|
self.app_state.set_current_exercise_ind(ind)?;
|
||||||
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue