Skip to content

Commit 4e12725

Browse files
committed
Don't exit the list on "to current" if nothing is selected
1 parent 570bc9f commit 4e12725

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/list.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
6363
list_state.reset_selected()?;
6464
}
6565
KeyCode::Char('c') => {
66-
return list_state.selected_to_current_exercise();
66+
if list_state.selected_to_current_exercise()? {
67+
return Ok(());
68+
}
6769
}
6870
// Redraw to remove the message.
6971
KeyCode::Esc => (),

src/list/state.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,25 +250,27 @@ impl<'a> ListState<'a> {
250250
Ok(())
251251
}
252252

253-
pub fn selected_to_current_exercise(&mut self) -> Result<()> {
253+
// Return `true` if there was something to select.
254+
pub fn selected_to_current_exercise(&mut self) -> Result<bool> {
254255
let Some(selected) = self.selected else {
255-
// TODO: Don't exit list
256-
return Ok(());
256+
self.message.push_str("Nothing selected to continue at!");
257+
return Ok(false);
257258
};
258259

259-
let ind = self
260+
let (ind, _) = self
260261
.app_state
261262
.exercises()
262263
.iter()
263264
.enumerate()
264-
.filter_map(|(ind, exercise)| match self.filter {
265-
Filter::Done => exercise.done.then_some(ind),
266-
Filter::Pending => (!exercise.done).then_some(ind),
267-
Filter::None => Some(ind),
265+
.filter(|(_, exercise)| match self.filter {
266+
Filter::Done => exercise.done,
267+
Filter::Pending => !exercise.done,
268+
Filter::None => true,
268269
})
269270
.nth(selected)
270271
.context("Invalid selection index")?;
271272

272-
self.app_state.set_current_exercise_ind(ind)
273+
self.app_state.set_current_exercise_ind(ind)?;
274+
Ok(true)
273275
}
274276
}

0 commit comments

Comments
 (0)