make initial score also behave positive
This commit is contained in:
parent
12dc85e928
commit
e18684e8a4
3 changed files with 11 additions and 10 deletions
|
@ -315,7 +315,6 @@ pub struct Config {
|
||||||
// #[serde(default = "default_text_wrap_length")]
|
// #[serde(default = "default_text_wrap_length")]
|
||||||
// #[clap(long = "text-wrap-length")]
|
// #[clap(long = "text-wrap-length")]
|
||||||
// pub text_wrap_length: Option<usize>,
|
// pub text_wrap_length: Option<usize>,
|
||||||
|
|
||||||
/// Defines how long it takes for the show animation to finish
|
/// Defines how long it takes for the show animation to finish
|
||||||
/// Defaults to 70ms
|
/// Defaults to 70ms
|
||||||
#[serde(default = "default_show_animation_time")]
|
#[serde(default = "default_show_animation_time")]
|
||||||
|
|
|
@ -14,8 +14,8 @@ use gdk4::prelude::{Cast, DisplayExt, MonitorExt};
|
||||||
use gdk4::{Display, Key};
|
use gdk4::{Display, Key};
|
||||||
use gtk4::glib::ControlFlow;
|
use gtk4::glib::ControlFlow;
|
||||||
use gtk4::prelude::{
|
use gtk4::prelude::{
|
||||||
ApplicationExt, ApplicationExtManual, BoxExt, EditableExt, FlowBoxChildExt,
|
ApplicationExt, ApplicationExtManual, BoxExt, EditableExt, FlowBoxChildExt, GestureSingleExt,
|
||||||
GestureSingleExt, GtkWindowExt, ListBoxRowExt, NativeExt, WidgetExt,
|
GtkWindowExt, ListBoxRowExt, NativeExt, WidgetExt,
|
||||||
};
|
};
|
||||||
use gtk4::{
|
use gtk4::{
|
||||||
Align, EventControllerKey, Expander, FlowBox, FlowBoxChild, GestureClick, Image, Label,
|
Align, EventControllerKey, Expander, FlowBox, FlowBoxChild, GestureClick, Image, Label,
|
||||||
|
@ -463,7 +463,7 @@ fn sort_menu_items_by_score<T: std::clone::Clone>(
|
||||||
} else {
|
} else {
|
||||||
Ordering::Larger
|
Ordering::Larger
|
||||||
}
|
}
|
||||||
} else if menu1.initial_sort_score < menu2.initial_sort_score {
|
} else if menu1.initial_sort_score > menu2.initial_sort_score {
|
||||||
Ordering::Smaller
|
Ordering::Smaller
|
||||||
} else {
|
} else {
|
||||||
Ordering::Larger
|
Ordering::Larger
|
||||||
|
@ -527,7 +527,6 @@ fn ease_in_out_cubic(t: f32) -> f32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn animate_window<Func>(
|
fn animate_window<Func>(
|
||||||
window: ApplicationWindow,
|
window: ApplicationWindow,
|
||||||
animation_time: u64,
|
animation_time: u64,
|
||||||
|
@ -820,7 +819,7 @@ fn set_menu_visibility_for_search<T: Clone>(
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
for menu_item in items.iter_mut() {
|
for menu_item in items.iter_mut() {
|
||||||
// todo make initial score and search score both follow same logic.
|
// todo make initial score and search score both follow same logic.
|
||||||
menu_item.search_sort_score = -menu_item.initial_sort_score as f64;
|
menu_item.search_sort_score = menu_item.initial_sort_score as f64;
|
||||||
menu_item.visible = true;
|
menu_item.visible = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -877,7 +876,7 @@ fn set_menu_visibility_for_search<T: Clone>(
|
||||||
|
|
||||||
// todo turn initial score init f64
|
// todo turn initial score init f64
|
||||||
menu_item.search_sort_score =
|
menu_item.search_sort_score =
|
||||||
search_sort_score - menu_item.initial_sort_score as f64;
|
search_sort_score + menu_item.initial_sort_score as f64;
|
||||||
menu_item.visible = visible;
|
menu_item.visible = visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -921,13 +920,16 @@ fn percent_or_absolute(value: Option<&String>, base_value: i32) -> Option<i32> {
|
||||||
pub fn sort_menu_items_alphabetically_honor_initial_score<T: std::clone::Clone>(
|
pub fn sort_menu_items_alphabetically_honor_initial_score<T: std::clone::Clone>(
|
||||||
items: &mut [MenuItem<T>],
|
items: &mut [MenuItem<T>],
|
||||||
) {
|
) {
|
||||||
let mut regular_score = items.len() as i64;
|
let special_score = items.len() as i64;
|
||||||
|
let mut regular_score = 0;
|
||||||
items.sort_by(|l, r| l.label.cmp(&r.label));
|
items.sort_by(|l, r| l.label.cmp(&r.label));
|
||||||
|
|
||||||
for item in items.iter_mut() {
|
for item in items.iter_mut() {
|
||||||
if item.initial_sort_score == 0 {
|
if item.initial_sort_score == 0 {
|
||||||
item.initial_sort_score = regular_score;
|
item.initial_sort_score += regular_score;
|
||||||
regular_score += 1;
|
regular_score += 1;
|
||||||
|
} else {
|
||||||
|
item.initial_sort_score += special_score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl<T: Clone> DRunProvider<T> {
|
||||||
action,
|
action,
|
||||||
sub_elements: Vec::default(),
|
sub_elements: Vec::default(),
|
||||||
working_dir: working_dir.clone(),
|
working_dir: working_dir.clone(),
|
||||||
initial_sort_score: -(*sort_score),
|
initial_sort_score: *sort_score,
|
||||||
search_sort_score: 0.0,
|
search_sort_score: 0.0,
|
||||||
data: Some(menu_item_data.clone()),
|
data: Some(menu_item_data.clone()),
|
||||||
visible: true,
|
visible: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue