Merge bce46a2295 into c8a47a068b
This commit is contained in:
commit
e033a98159
|
|
@ -180,6 +180,25 @@ impl Database {
|
||||||
self.with_dirty_mut(|dirty| *dirty = true);
|
self.with_dirty_mut(|dirty| *dirty = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sort_by_keywords(&mut self, keywords: &[String]) {
|
||||||
|
if keywords.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.with_dirs_mut(|dirs| {
|
||||||
|
dirs.sort_by_key(|dir| Self::has_exact_match(&dir.path, keywords));
|
||||||
|
});
|
||||||
|
self.with_dirty_mut(|dirty| *dirty = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_exact_match(path: &str, keywords: &[String]) -> bool {
|
||||||
|
keywords.last().is_some_and(|keyword| {
|
||||||
|
let path_lower = util::to_lowercase(path);
|
||||||
|
let last_component = path_lower.rsplit(std::path::is_separator).next().unwrap_or("");
|
||||||
|
last_component == keyword
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dirty(&self) -> bool {
|
pub fn dirty(&self) -> bool {
|
||||||
*self.borrow_dirty()
|
*self.borrow_dirty()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@ pub struct Stream<'a> {
|
||||||
|
|
||||||
impl<'a> Stream<'a> {
|
impl<'a> Stream<'a> {
|
||||||
pub fn new(db: &'a mut Database, options: StreamOptions) -> Self {
|
pub fn new(db: &'a mut Database, options: StreamOptions) -> Self {
|
||||||
db.sort_by_score(options.now);
|
let now = options.now;
|
||||||
|
let keywords = &options.keywords;
|
||||||
|
|
||||||
|
db.sort_by_score(now);
|
||||||
|
db.sort_by_keywords(keywords);
|
||||||
let idxs = (0..db.dirs().len()).rev();
|
let idxs = (0..db.dirs().len()).rev();
|
||||||
Stream { db, idxs, options }
|
Stream { db, idxs, options }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue