parent
e3ee26f8b3
commit
3945368184
1 changed files with 63 additions and 62 deletions
125
src/lib/gui.rs
125
src/lib/gui.rs
|
@ -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();
|
||||||
query.pop();
|
if !query.is_empty() {
|
||||||
|
query.pop();
|
||||||
|
}
|
||||||
search_entry.set_text(&query);
|
search_entry.set_text(&query);
|
||||||
update_view_from_provider(&query);
|
update_view_from_provider(&query);
|
||||||
}
|
}
|
||||||
|
@ -861,72 +862,72 @@ 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 {
|
||||||
|
let query = query.to_owned().to_lowercase(); // todo match case senstive according to conf
|
||||||
|
for (flowbox_child, menu_item) in items.iter_mut() {
|
||||||
|
let menu_item_search = format!(
|
||||||
|
"{} {}",
|
||||||
|
menu_item
|
||||||
|
.action
|
||||||
|
.as_ref()
|
||||||
|
.map(|a| a.to_lowercase())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
&menu_item.label.to_lowercase()
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(child) = inner_box.first_child() {
|
let matching = if let Some(matching) = &config.matching {
|
||||||
child.grab_focus();
|
matching
|
||||||
let fb = child.downcast::<FlowBoxChild>();
|
} else {
|
||||||
if let Ok(fb) = fb {
|
&config::default_match_method().unwrap()
|
||||||
inner_box.select_child(&fb);
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let query = query.to_owned().to_lowercase();
|
let (search_sort_score, visible) = match matching {
|
||||||
for (flowbox_child, menu_item) in items.iter_mut() {
|
MatchMethod::Fuzzy => {
|
||||||
let menu_item_search = format!(
|
let mut score = strsim::jaro_winkler(&query, &menu_item_search);
|
||||||
"{} {}",
|
if score == 0.0 {
|
||||||
menu_item
|
score = -1.0;
|
||||||
.action
|
}
|
||||||
.as_ref()
|
|
||||||
.map(|a| a.to_lowercase())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
&menu_item.label.to_lowercase()
|
|
||||||
);
|
|
||||||
|
|
||||||
let matching = if let Some(matching) = &config.matching {
|
(
|
||||||
matching
|
score,
|
||||||
} else {
|
score
|
||||||
&config::default_match_method().unwrap()
|
> config
|
||||||
};
|
.fuzzy_min_score
|
||||||
|
.unwrap_or(config::default_fuzzy_min_score().unwrap_or(0.0))
|
||||||
let (search_sort_score, visible) = match matching {
|
&& score > 0.0,
|
||||||
MatchMethod::Fuzzy => {
|
)
|
||||||
let score = strsim::normalized_levenshtein(&query, &menu_item_search);
|
|
||||||
(
|
|
||||||
score,
|
|
||||||
score
|
|
||||||
> config
|
|
||||||
.fuzzy_min_score
|
|
||||||
.unwrap_or(config::default_fuzzy_min_score().unwrap_or(0.0)) && score > 0.0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
MatchMethod::Contains => {
|
|
||||||
if menu_item_search.contains(&query) {
|
|
||||||
(1.0, true)
|
|
||||||
} else {
|
|
||||||
(0.0, false)
|
|
||||||
}
|
}
|
||||||
}
|
MatchMethod::Contains => {
|
||||||
MatchMethod::MultiContains => {
|
if menu_item_search.contains(&query) {
|
||||||
let score = query
|
(1.0, true)
|
||||||
.split(' ')
|
} else {
|
||||||
.filter(|i| menu_item_search.contains(i))
|
(0.0, false)
|
||||||
.map(|_| 1.0)
|
}
|
||||||
.sum();
|
}
|
||||||
(score, score > 0.0)
|
MatchMethod::MultiContains => {
|
||||||
}
|
let score = query
|
||||||
};
|
.split(' ')
|
||||||
|
.filter(|i| menu_item_search.contains(i))
|
||||||
|
.map(|_| 1.0)
|
||||||
|
.sum();
|
||||||
|
(score, score > 0.0)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
|
"menu item {}, search score {}",
|
||||||
|
menu_item_search,
|
||||||
|
search_sort_score
|
||||||
|
);
|
||||||
|
|
||||||
log::debug!("menu item {}, search score {}", menu_item_search, search_sort_score);
|
menu_item.search_sort_score = search_sort_score;
|
||||||
|
flowbox_child.set_visible(visible);
|
||||||
menu_item.search_sort_score = search_sort_score;
|
}
|
||||||
flowbox_child.set_visible(visible);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue