Skip to content

Commit

Permalink
Merge pull request #25 from mfontanini/hot-reload-jumps
Browse files Browse the repository at this point in the history
Jump to slide if layout changes
  • Loading branch information
mfontanini authored Oct 24, 2023
2 parents 80b0561 + ce8f378 commit eb72a11
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl ContentDiff for RenderOperation {
}
(RenderImage(original), RenderImage(updated)) if original != updated => true,
(RenderPreformattedLine(original), RenderPreformattedLine(updated)) if original != updated => true,
(InitColumnLayout { columns: original }, InitColumnLayout { columns: updated }) if original != updated => {
true
}
(EnterColumn { column: original }, EnterColumn { column: updated }) if original != updated => true,
// This is only used for footers which are global. Ignore for now.
(RenderDynamic(_), RenderDynamic(_)) => false,
_ => false,
Expand Down Expand Up @@ -136,6 +140,9 @@ mod test {
}
))]
#[case(RenderOperation::RenderDynamic(Rc::new(Dynamic)))]
#[case(RenderOperation::InitColumnLayout{ columns: vec![1, 2] })]
#[case(RenderOperation::EnterColumn{ column: 1 })]
#[case(RenderOperation::ExitLayout)]
fn same_not_modified(#[case] operation: RenderOperation) {
let diff = operation.is_content_different(&operation);
assert!(!diff);
Expand Down Expand Up @@ -168,6 +175,20 @@ mod test {
assert!(!lhs.is_content_different(&rhs));
}

#[test]
fn different_column_layout() {
let lhs = RenderOperation::InitColumnLayout { columns: vec![1, 2] };
let rhs = RenderOperation::InitColumnLayout { columns: vec![1, 3] };
assert!(lhs.is_content_different(&rhs));
}

#[test]
fn different_column() {
let lhs = RenderOperation::EnterColumn { column: 0 };
let rhs = RenderOperation::EnterColumn { column: 1 };
assert!(lhs.is_content_different(&rhs));
}

#[test]
fn no_slide_changes() {
let presentation = Presentation::new(vec![
Expand Down
9 changes: 9 additions & 0 deletions src/presentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl Presentation {
self.current_slide_mut().jump_chunk(chunk_index);
}

/// Get the current slide's chunk.
pub(crate) fn current_chunk(&self) -> usize {
self.current_slide().current_chunk()
}

/// Render all widgets in this slide.
pub(crate) fn render_slide_widgets(&mut self) -> bool {
let slide = self.current_slide_mut();
Expand Down Expand Up @@ -170,6 +175,10 @@ impl Slide {
self.visible_chunks = (chunk_index + 1).min(self.chunks.len());
}

fn current_chunk(&self) -> usize {
self.visible_chunks.saturating_sub(1)
}

fn show_first_chunk(&mut self) {
self.visible_chunks = 1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/presenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ impl<'a> Presenter<'a> {
if let Some(modification) = PresentationDiffer::find_first_modification(current, &presentation) {
presentation.jump_slide(modification.slide_index);
presentation.jump_chunk(modification.chunk_index);
} else {
presentation.jump_slide(current.current_slide_index());
presentation.jump_chunk(current.current_chunk());
}
self.state = PresenterState::Presenting(presentation)
}
Expand Down

0 comments on commit eb72a11

Please sign in to comment.