diff options
| author | mo8it <mo8it@proton.me> | 2024-08-24 00:23:45 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-08-24 00:23:45 +0200 |
| commit | 4e12725616abe1918d6a4f21b23288dfac237cc4 (patch) | |
| tree | 638eabc75f99c3496b671955ee4518ec5e3e988e /src/list/state.rs | |
| parent | 570bc9f32d7ef0bf741fab44d15f7cd54a1f3fc1 (diff) | |
Don't exit the list on "to current" if nothing is selected
Diffstat (limited to 'src/list/state.rs')
| -rw-r--r-- | src/list/state.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/list/state.rs b/src/list/state.rs index cf147b4..645c768 100644 --- a/src/list/state.rs +++ b/src/list/state.rs @@ -250,25 +250,27 @@ impl<'a> ListState<'a> { 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 { - // TODO: Don't exit list - return Ok(()); + self.message.push_str("Nothing selected to continue at!"); + return Ok(false); }; - let ind = self + let (ind, _) = self .app_state .exercises() .iter() .enumerate() - .filter_map(|(ind, exercise)| match self.filter { - Filter::Done => exercise.done.then_some(ind), - Filter::Pending => (!exercise.done).then_some(ind), - Filter::None => Some(ind), + .filter(|(_, exercise)| match self.filter { + Filter::Done => exercise.done, + Filter::Pending => !exercise.done, + Filter::None => true, }) .nth(selected) .context("Invalid selection index")?; - self.app_state.set_current_exercise_ind(ind) + self.app_state.set_current_exercise_ind(ind)?; + Ok(true) } } |
