Panics · P09 Overlays: a lightbox or tour past its last item closes
This commit is contained in:
1 parent
7af7c409c9
commit
8f00d2eabb
4 files changed
+35
-15
No files matched your search
@@ -96,15 +96,9 @@ impl Lightbox {
|
||||
at: usize,
|
||||
on_close: impl Fn(&mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
let slides: Vec<Slide> = slides.into_iter().collect();
|
||||
assert!(
|
||||
slides.is_empty() || at < slides.len(),
|
||||
"slide {at} is past the last of {}",
|
||||
slides.len()
|
||||
);
|
||||
Self {
|
||||
id: id.into(),
|
||||
slides,
|
||||
slides: slides.into_iter().collect(),
|
||||
at,
|
||||
on_step: None,
|
||||
on_close: Rc::new(on_close),
|
||||
@@ -140,6 +134,14 @@ impl RenderOnce for Lightbox {
|
||||
window.defer(cx, move |window, cx| close(window, cx));
|
||||
return div().into_any_element();
|
||||
}
|
||||
if at >= count {
|
||||
log::error!(
|
||||
"lightbox {:?}: slide {at} of {count} is gone; closing",
|
||||
self.id
|
||||
);
|
||||
window.defer(cx, move |window, cx| close(window, cx));
|
||||
return div().into_any_element();
|
||||
}
|
||||
let step: OnStep = {
|
||||
let (id, on_step) = (self.id.clone(), self.on_step);
|
||||
Rc::new(move |to, window, cx| {
|
||||
|
||||
@@ -318,15 +318,9 @@ impl Tour {
|
||||
at: usize,
|
||||
on_close: impl Fn(&mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
let steps: Vec<TourStep> = steps.into_iter().collect();
|
||||
assert!(
|
||||
at < steps.len(),
|
||||
"step {at} is past the last of {}",
|
||||
steps.len()
|
||||
);
|
||||
Self {
|
||||
id: id.into(),
|
||||
steps,
|
||||
steps: steps.into_iter().collect(),
|
||||
at,
|
||||
on_step: None,
|
||||
on_close: Rc::new(on_close),
|
||||
@@ -361,6 +355,11 @@ impl RenderOnce for Tour {
|
||||
}
|
||||
})
|
||||
};
|
||||
if at >= count {
|
||||
log::error!("tour {:?}: step {at} of {count} is gone; closing", self.id);
|
||||
window.defer(cx, move |window, cx| close(window, cx));
|
||||
return div().into_any_element();
|
||||
}
|
||||
let (back, next) = (at.checked_sub(1), (at + 1 < count).then_some(at + 1));
|
||||
let current = self.steps[at].clone();
|
||||
let turn = motion::changes((self.id.clone(), "at"), at, window, cx);
|
||||
|
||||
@@ -352,3 +352,21 @@ fn left_from_back_keeps_the_tour_keys(cx: &mut TestAppContext) {
|
||||
press("right", cx);
|
||||
assert_eq!(state(&view, cx).1, 1);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_lightbox_or_tour_past_its_last_closes(cx: &mut TestAppContext) {
|
||||
let (view, cx) = guides(cx);
|
||||
for open in [Open::Lightbox, Open::Tour] {
|
||||
view.update(cx, |guides, cx| {
|
||||
guides.open = Some(open);
|
||||
guides.at = 5;
|
||||
cx.notify();
|
||||
});
|
||||
settle(cx);
|
||||
assert_eq!(
|
||||
view.read_with(cx, |guides, _| guides.open),
|
||||
None,
|
||||
"{open:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user