fix(pomodoro): ctrl+r resets rounds + both clocks (#83)

This commit is contained in:
Jens Krause 2025-05-20 10:01:29 +02:00 committed by GitHub
parent 5f4c5bb8ed
commit d27587a44a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -8,6 +8,7 @@
### Fixes
- (pomodoro) `ctrl+r` resets rounds AND both clocks [#83](https://github.com/sectore/tick-tock-tui/pull/83)
- (pomodoro) reset active clock only [#82](https://github.com/sectore/tick-tock-tui/pull/82)
## v1.3.0 - 2025-05-06

View File

@ -158,12 +158,12 @@ impl StatefulWidget for Footer {
}
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[r]eset"),
Span::from("[r]eset clock"),
]);
if self.selected_content == Content::Pomodoro {
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[^r]eset round"),
Span::from("[^r]eset clocks+rounds"),
]);
}
spans

View File

@ -107,10 +107,18 @@ impl PomodoroState {
&self.clock_map.work
}
pub fn get_clock_work_mut(&mut self) -> &mut ClockState<Countdown> {
self.clock_map.get_mut(&Mode::Work)
}
pub fn get_clock_pause(&self) -> &ClockState<Countdown> {
&self.clock_map.pause
}
pub fn get_clock_pause_mut(&mut self) -> &mut ClockState<Countdown> {
self.clock_map.get_mut(&Mode::Pause)
}
pub fn get_mode(&self) -> &Mode {
&self.mode
}
@ -198,13 +206,15 @@ impl TuiEventHandler for PomodoroState {
KeyCode::Right => {
self.next();
}
// reset round
// reset rounds AND clocks
KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => {
self.round = 1;
self.get_clock_work_mut().reset();
self.get_clock_pause_mut().reset();
}
// reset values
// reset current clock
KeyCode::Char('r') => {
// count number of finished rounds of WORK before resetting the clock
// increase round before (!!) resetting the clock
if self.get_mode() == &Mode::Work && self.get_clock().is_done() {
self.round += 1;
}