Skip to content

Commit a8a9208

Browse files
committed
fix: address CodeRabbit review issues
- Prevent Esc from opening menu in Finished state - Avoid restoring stale WaitingForNext deadline on menu close - Store resume step index (next step) in checkpoint to avoid re-executing boundary steps - Capture speed_ms in ManualCheckpoint for correct speed after cross-file restore
1 parent 75c1266 commit a8a9208

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎src/animation.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,17 @@ struct ManualCheckpoint {
235235
line_offset: isize,
236236
dialog_title: Option<String>,
237237
dialog_typing_text: String,
238+
speed_ms: u64,
238239
}
239240

240241
impl ManualCheckpoint {
241242
fn new(engine: &AnimationEngine) -> Self {
243+
let resume_step = engine
244+
.current_step
245+
.saturating_add(1)
246+
.min(engine.steps.len());
242247
Self {
243-
step_index: engine.current_step,
248+
step_index: resume_step,
244249
buffer: engine.buffer.clone(),
245250
current_file_index: engine.current_file_index,
246251
current_file_path: engine.current_file_path.clone(),
@@ -249,6 +254,7 @@ impl ManualCheckpoint {
249254
line_offset: engine.line_offset,
250255
dialog_title: engine.dialog_title.clone(),
251256
dialog_typing_text: engine.dialog_typing_text.clone(),
257+
speed_ms: engine.speed_ms,
252258
}
253259
}
254260
}
@@ -432,6 +438,7 @@ impl AnimationEngine {
432438
self.line_offset = snapshot.line_offset;
433439
self.dialog_title = snapshot.dialog_title;
434440
self.dialog_typing_text = snapshot.dialog_typing_text;
441+
self.speed_ms = snapshot.speed_ms;
435442
self.pause_until = None;
436443
self.paused = true;
437444
self.state = AnimationState::Playing;

‎src/ui.rs‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ impl<'a> UI<'a> {
121121
}
122122

123123
fn close_menu(&mut self) {
124-
if let Some(prev) = self.prev_state.take() {
125-
self.state = *prev;
126-
} else {
127-
self.state = UIState::Playing;
128-
}
124+
let restored = self
125+
.prev_state
126+
.take()
127+
.map(|s| *s)
128+
.unwrap_or(UIState::Playing);
129+
self.state = match restored {
130+
UIState::WaitingForNext { .. } => UIState::Playing,
131+
other => other,
132+
};
129133
if self.playback_state == PlaybackState::Playing {
130134
self.engine.resume();
131135
}
@@ -394,6 +398,15 @@ impl<'a> UI<'a> {
394398
}
395399
_ => {}
396400
},
401+
UIState::Finished => match key.code {
402+
KeyCode::Char('q') => {
403+
self.state = UIState::Finished;
404+
}
405+
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
406+
self.state = UIState::Finished;
407+
}
408+
_ => {}
409+
},
397410
_ => match key.code {
398411
KeyCode::Esc => self.open_menu(),
399412
KeyCode::Char('q') => {

0 commit comments

Comments
 (0)