|
|
|
@ -74,15 +74,15 @@ impl<T: Item> Menu<T> {
|
|
|
|
|
// rendering)
|
|
|
|
|
pub fn new(
|
|
|
|
|
options: Vec<T>,
|
|
|
|
|
sort: bool,
|
|
|
|
|
editor_data: <T as Item>::Data,
|
|
|
|
|
callback_fn: impl Fn(&mut Editor, Option<&T>, MenuEvent) + 'static,
|
|
|
|
|
) -> Self {
|
|
|
|
|
let mut menu = Self {
|
|
|
|
|
let matches = (0..options.len()).map(|i| (i, 0)).collect();
|
|
|
|
|
Self {
|
|
|
|
|
options,
|
|
|
|
|
editor_data,
|
|
|
|
|
matcher: Box::new(Matcher::default()),
|
|
|
|
|
matches: Vec::new(),
|
|
|
|
|
matches,
|
|
|
|
|
cursor: None,
|
|
|
|
|
widths: Vec::new(),
|
|
|
|
|
callback_fn: Box::new(callback_fn),
|
|
|
|
@ -90,16 +90,7 @@ impl<T: Item> Menu<T> {
|
|
|
|
|
size: (0, 0),
|
|
|
|
|
viewport: (0, 0),
|
|
|
|
|
recalculate: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if sort {
|
|
|
|
|
// TODO: scoring on empty input should just use a fastpath
|
|
|
|
|
menu.score("");
|
|
|
|
|
} else {
|
|
|
|
|
menu.matches = (0..menu.options.len()).map(|i| (i, 0)).collect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn score(&mut self, pattern: &str) {
|
|
|
|
|