Better prioritisation
This commit is contained in:
parent
846cc31174
commit
5901a6cd1f
2 changed files with 10 additions and 10 deletions
|
|
@ -120,7 +120,7 @@ impl<T> Options<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_options<F: FnMut(&T) -> Option<u32>>(
|
||||
pub fn set_options<F: FnMut(&T) -> Option<S>, S: Ord + Copy>(
|
||||
&mut self,
|
||||
options: impl IntoIterator<Item = T>,
|
||||
mut f: F,
|
||||
|
|
@ -129,14 +129,14 @@ impl<T> Options<T> {
|
|||
self.apply_scoring(f);
|
||||
}
|
||||
|
||||
pub fn apply_scoring<F: FnMut(&T) -> Option<u32>>(&mut self, mut f: F) {
|
||||
pub fn apply_scoring<F: FnMut(&T) -> Option<S>, S: Ord + Copy>(&mut self, mut f: F) {
|
||||
let mut ranking = self
|
||||
.options
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, o)| Some((i, f(o)?)))
|
||||
.collect::<Vec<_>>();
|
||||
ranking.sort_by_key(|(_, score)| std::cmp::Reverse(*score));
|
||||
ranking.sort_by_key(|(_, score)| *score);
|
||||
self.ranking = ranking.into_iter().map(|(i, _)| i).collect();
|
||||
self.selected = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,9 +232,9 @@ impl Element<()> for Switcher {
|
|||
};
|
||||
let name = buffer.name()?;
|
||||
if name.starts_with(&filter) {
|
||||
Some(2)
|
||||
} else if name.contains(&filter) {
|
||||
Some(1)
|
||||
} else if name.contains(&filter) {
|
||||
Some(2)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -341,19 +341,19 @@ impl Opener {
|
|||
let name = e.path.file_name()?.to_str()?.to_lowercase();
|
||||
if matches!(e.kind, FileKind::New) {
|
||||
// Special-case: the 'new file' entry always matches last
|
||||
Some(0)
|
||||
Some((3, name.chars().count()))
|
||||
} else if name == filter {
|
||||
Some(3)
|
||||
Some((0, name.chars().count()))
|
||||
} else if name.starts_with(&filter) {
|
||||
Some(2)
|
||||
Some((1, name.chars().count()))
|
||||
} else if name.contains(&filter) {
|
||||
Some(1)
|
||||
Some((2, name.chars().count()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
Err(err) => self.options.set_options(Vec::new(), |_| None),
|
||||
Err(err) => self.options.set_options::<_, ()>(Vec::new(), |_| None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue