parent
e3ee26f8b3
commit
3945368184
1 changed files with 63 additions and 62 deletions
|
@ -263,6 +263,7 @@ fn build_ui_from_menu_items<T: Clone + 'static>(
|
||||||
|
|
||||||
while let Some(b) = inner_box.child_at_index(0) {
|
while let Some(b) = inner_box.child_at_index(0) {
|
||||||
inner_box.remove(&b);
|
inner_box.remove(&b);
|
||||||
|
drop(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry in items {
|
for entry in items {
|
||||||
|
@ -274,7 +275,6 @@ fn build_ui_from_menu_items<T: Clone + 'static>(
|
||||||
}
|
}
|
||||||
let lic = ArcMenuMap::clone(list_items);
|
let lic = ArcMenuMap::clone(list_items);
|
||||||
inner_box.set_sort_func(move |child2, child1| sort_menu_items_by_score(child1, child2, &lic));
|
inner_box.set_sort_func(move |child2, child1| sort_menu_items_by_score(child1, child2, &lic));
|
||||||
inner_box.invalidate_sort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)] // todo fix this
|
#[allow(clippy::too_many_arguments)] // todo fix this
|
||||||
|
@ -361,8 +361,9 @@ fn handle_key_press<T: Clone + 'static>(
|
||||||
}
|
}
|
||||||
Key::BackSpace => {
|
Key::BackSpace => {
|
||||||
let mut query = search_entry.text().to_string();
|
let mut query = search_entry.text().to_string();
|
||||||
|
if !query.is_empty() {
|
||||||
query.pop();
|
query.pop();
|
||||||
|
}
|
||||||
search_entry.set_text(&query);
|
search_entry.set_text(&query);
|
||||||
update_view_from_provider(&query);
|
update_view_from_provider(&query);
|
||||||
}
|
}
|
||||||
|
@ -861,22 +862,13 @@ fn filter_widgets<T: Clone>(
|
||||||
) {
|
) {
|
||||||
{
|
{
|
||||||
let mut items = item_arc.lock().unwrap();
|
let mut items = item_arc.lock().unwrap();
|
||||||
if items.is_empty() {
|
if query.is_empty() {
|
||||||
for (child, _) in items.iter() {
|
for (flowbox_child, menu_item) in items.iter_mut() {
|
||||||
child.set_visible(true);
|
flowbox_child.set_visible(true);
|
||||||
|
menu_item.search_sort_score = -1.0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if let Some(child) = inner_box.first_child() {
|
let query = query.to_owned().to_lowercase(); // todo match case senstive according to conf
|
||||||
child.grab_focus();
|
|
||||||
let fb = child.downcast::<FlowBoxChild>();
|
|
||||||
if let Ok(fb) = fb {
|
|
||||||
inner_box.select_child(&fb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let query = query.to_owned().to_lowercase();
|
|
||||||
for (flowbox_child, menu_item) in items.iter_mut() {
|
for (flowbox_child, menu_item) in items.iter_mut() {
|
||||||
let menu_item_search = format!(
|
let menu_item_search = format!(
|
||||||
"{} {}",
|
"{} {}",
|
||||||
|
@ -896,13 +888,18 @@ fn filter_widgets<T: Clone>(
|
||||||
|
|
||||||
let (search_sort_score, visible) = match matching {
|
let (search_sort_score, visible) = match matching {
|
||||||
MatchMethod::Fuzzy => {
|
MatchMethod::Fuzzy => {
|
||||||
let score = strsim::normalized_levenshtein(&query, &menu_item_search);
|
let mut score = strsim::jaro_winkler(&query, &menu_item_search);
|
||||||
|
if score == 0.0 {
|
||||||
|
score = -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
score,
|
score,
|
||||||
score
|
score
|
||||||
> config
|
> config
|
||||||
.fuzzy_min_score
|
.fuzzy_min_score
|
||||||
.unwrap_or(config::default_fuzzy_min_score().unwrap_or(0.0)) && score > 0.0,
|
.unwrap_or(config::default_fuzzy_min_score().unwrap_or(0.0))
|
||||||
|
&& score > 0.0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MatchMethod::Contains => {
|
MatchMethod::Contains => {
|
||||||
|
@ -922,13 +919,17 @@ fn filter_widgets<T: Clone>(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
log::debug!("menu item {}, search score {}", menu_item_search, search_sort_score);
|
"menu item {}, search score {}",
|
||||||
|
menu_item_search,
|
||||||
|
search_sort_score
|
||||||
|
);
|
||||||
|
|
||||||
menu_item.search_sort_score = search_sort_score;
|
menu_item.search_sort_score = search_sort_score;
|
||||||
flowbox_child.set_visible(visible);
|
flowbox_child.set_visible(visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner_box.invalidate_sort();
|
inner_box.invalidate_sort();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue