Skip to content

Commit 935e363

Browse files
committed
feat: respect pause in speaker notes
1 parent 41049da commit 935e363

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

src/commands/keyboard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl CommandKeyBindings {
9696
ToggleLayoutGrid => Command::ToggleLayoutGrid,
9797
CloseModal => Command::CloseModal,
9898
SkipPauses => Command::SkipPauses,
99+
GoToSlideChunk => panic!("go to slide chunk is not configurable"),
99100
};
100101
InputAction::Emit(command)
101102
}

src/commands/listener.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl CommandListener {
3030
if let Some(receiver) = &self.speaker_notes_event_listener {
3131
if let Some(msg) = receiver.try_recv()? {
3232
let command = match msg {
33-
SpeakerNotesEvent::GoToSlide { slide } => Command::GoToSlide(slide),
33+
SpeakerNotesEvent::GoTo { slide, chunk } => Command::GoToSlideChunk { slide, chunk },
3434
SpeakerNotesEvent::Exit => Command::Exit,
3535
};
3636
return Ok(Some(command));
@@ -73,6 +73,9 @@ pub(crate) enum Command {
7373
/// Go to one particular slide.
7474
GoToSlide(u32),
7575

76+
/// Go to one particular slide + chunk.
77+
GoToSlideChunk { slide: u32, chunk: u32 },
78+
7679
/// Render any async render operations in the current slide.
7780
RenderAsyncOperations,
7881

src/commands/speaker_notes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl SpeakerNotesEventListener {
6868
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
6969
#[serde(tag = "command")]
7070
pub(crate) enum SpeakerNotesEvent {
71-
GoToSlide { slide: u32 },
71+
GoTo { slide: u32, chunk: u32 },
7272
Exit,
7373
}
7474

src/presentation/builder/comment.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ impl PresentationBuilder<'_, '_> {
129129
self.push_text(line.into(), ElementType::Paragraph);
130130
self.push_line_break();
131131
}
132+
self.push_line_break();
132133
}
133134
CommentCommand::EndSlide => self.terminate_slide(),
135+
CommentCommand::Pause => self.push_pause(),
134136
CommentCommand::SkipSlide => self.slide_state.skip_slide = true,
135137
_ => {}
136138
}
@@ -621,8 +623,23 @@ hi
621623
<!-- speaker_note: bye -->
622624
";
623625
let options = PresentationBuilderOptions { render_speaker_notes_only: true, ..Default::default() };
624-
let lines = Test::new(input).options(options).render().rows(3).columns(3).into_lines();
625-
let expected = &[" ", "hi ", "bye"];
626+
let lines = Test::new(input).options(options).render().rows(4).columns(3).into_lines();
627+
let expected = &[" ", "hi ", " ", "bye"];
628+
assert_eq!(lines, expected);
629+
}
630+
631+
#[test]
632+
fn speaker_notes_pause() {
633+
let input = "
634+
<!-- speaker_note: hi -->
635+
636+
<!-- pause -->
637+
638+
<!-- speaker_note: bye -->
639+
";
640+
let options = PresentationBuilderOptions { render_speaker_notes_only: true, ..Default::default() };
641+
let lines = Test::new(input).options(options).render().rows(4).columns(3).advances(0).into_lines();
642+
let expected = &[" ", "hi ", " ", " "];
626643
assert_eq!(lines, expected);
627644
}
628645

src/presentation/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ impl Slide {
268268
self.chunks.iter()
269269
}
270270

271-
fn jump_chunk(&mut self, chunk_index: usize) {
271+
pub(crate) fn current_chunk_index(&self) -> usize {
272+
self.visible_chunks.saturating_sub(1)
273+
}
274+
275+
pub(crate) fn jump_chunk(&mut self, chunk_index: usize) {
272276
self.visible_chunks = chunk_index.saturating_add(1).min(self.chunks.len());
273277
for chunk in self.chunks.iter().take(self.visible_chunks - 1) {
274278
chunk.apply_all_mutations();
275279
}
276280
}
277281

278-
fn current_chunk_index(&self) -> usize {
279-
self.visible_chunks.saturating_sub(1)
280-
}
281-
282282
fn current_chunk(&self) -> &SlideChunk {
283283
&self.chunks[self.current_chunk_index()]
284284
}

src/presenter.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ impl<'a> Presenter<'a> {
165165
CommandSideEffect::None => (),
166166
};
167167
}
168-
self.publish_event(SpeakerNotesEvent::GoToSlide {
169-
slide: self.state.presentation().current_slide_index() as u32 + 1,
168+
let slide_index = self.state.presentation().current_slide_index() as u32 + 1;
169+
let slide = self.state.presentation().current_slide();
170+
self.publish_event(SpeakerNotesEvent::GoTo {
171+
slide: slide_index,
172+
chunk: slide.current_chunk_index() as u32,
170173
})?;
171174
}
172175
}
@@ -310,6 +313,11 @@ impl<'a> Presenter<'a> {
310313
Command::FirstSlide => presentation.jump_first_slide(),
311314
Command::LastSlide => presentation.jump_last_slide(),
312315
Command::GoToSlide(number) => presentation.go_to_slide(number.saturating_sub(1) as usize),
316+
Command::GoToSlideChunk { slide, chunk } => {
317+
presentation.go_to_slide(slide.saturating_sub(1) as usize);
318+
presentation.current_slide_mut().jump_chunk(chunk as usize);
319+
true
320+
}
313321
Command::RenderAsyncOperations => {
314322
let pollables = Self::trigger_slide_async_renders(presentation);
315323
if !pollables.is_empty() {

0 commit comments

Comments
 (0)