fix(dropdown::multi): panic on missing paragraph

This commit is contained in:
Michael Aaron Murphy 2023-12-09 01:15:47 +01:00
parent 2b9e0c09ee
commit 48610a909b
No known key found for this signature in database
GPG key ID: B2732D4240C9212C

View file

@ -443,11 +443,17 @@ pub fn overlay<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static
} }
super::menu::OptionElement::Option((option, item)) => { super::menu::OptionElement::Option((option, item)) => {
let selection_index = state let selection_index = state.selections.iter().position(|(i, _)| i == item);
let selection_index = match selection_index {
Some(index) => index,
None => {
state
.selections .selections
.iter() .push((item.clone(), crate::Paragraph::new()));
.position(|(i, _)| i == item) state.selections.len() - 1
.expect("selection missing from state"); }
};
let paragraph = &mut state.selections[selection_index].1; let paragraph = &mut state.selections[selection_index].1;