mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
Don't skip exercises on file changes
This commit is contained in:
parent
17a2d42ffd
commit
4ae3fcc3ca
@ -198,6 +198,10 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_exercise_ind(&mut self, exercise_ind: usize) -> Result<()> {
|
pub fn set_current_exercise_ind(&mut self, exercise_ind: usize) -> Result<()> {
|
||||||
|
if exercise_ind == self.current_exercise_ind {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
if exercise_ind >= self.exercises.len() {
|
if exercise_ind >= self.exercises.len() {
|
||||||
bail!(BAD_INDEX_ERR);
|
bail!(BAD_INDEX_ERR);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ pub fn watch(
|
|||||||
WatchEvent::Input(InputEvent::Run) => watch_state.run_current_exercise()?,
|
WatchEvent::Input(InputEvent::Run) => watch_state.run_current_exercise()?,
|
||||||
WatchEvent::Input(InputEvent::Unrecognized) => watch_state.render()?,
|
WatchEvent::Input(InputEvent::Unrecognized) => watch_state.render()?,
|
||||||
WatchEvent::FileChange { exercise_ind } => {
|
WatchEvent::FileChange { exercise_ind } => {
|
||||||
watch_state.run_exercise_with_ind(exercise_ind)?;
|
watch_state.handle_file_change(exercise_ind)?;
|
||||||
}
|
}
|
||||||
WatchEvent::TerminalResize => {
|
WatchEvent::TerminalResize => {
|
||||||
watch_state.render()?;
|
watch_state.render()?;
|
||||||
|
@ -72,7 +72,14 @@ impl<'a> WatchState<'a> {
|
|||||||
self.render()
|
self.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_exercise_with_ind(&mut self, exercise_ind: usize) -> Result<()> {
|
pub fn handle_file_change(&mut self, exercise_ind: usize) -> Result<()> {
|
||||||
|
// Don't skip exercises on file changes to avoid confusion from missing exercises.
|
||||||
|
// Skipping exercises must be explicit in the interactive list.
|
||||||
|
// But going back to an earlier exercise on file change is fine.
|
||||||
|
if self.app_state.current_exercise_ind() < exercise_ind {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
self.app_state.set_current_exercise_ind(exercise_ind)?;
|
self.app_state.set_current_exercise_ind(exercise_ind)?;
|
||||||
self.run_current_exercise()
|
self.run_current_exercise()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user