Sort fuzzy_matcher results based on score (#1183)

Co-authored-by: Stephan D <776816+extrawurst@users.noreply.github.com>
This commit is contained in:
Luka Markušić 2022-04-24 20:11:26 +02:00 committed by GitHub
parent 5f466ff983
commit 638d7c2648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* tabs indentation in blame [[@fersilva16](https://github.com/fersilva16)] ([#1111](https://github.com/extrawurst/gitui/issues/1117))
* switch focus to index after staging last file ([#1169](https://github.com/extrawurst/gitui/pull/1169))
* fix stashlist multi marking not updated after dropping ([#1207](https://github.com/extrawurst/gitui/pull/1207))
* exact matches have a higher priority and are placed to the top of the list when fuzzily finding files ([#1183](https://github.com/extrawurst/gitui/pull/1183))
## [0.20.1] - 2021-01-26

View file

@ -88,15 +88,18 @@ impl FileFindPopup {
let matcher =
fuzzy_matcher::skim::SkimMatcherV2::default();
self.files_filtered.extend(
let mut files =
self.files.iter().enumerate().filter_map(|a| {
a.1.path.to_str().and_then(|path| {
matcher
.fuzzy_indices(path, q)
.map(|(_, indicies)| (a.0, indicies))
.map(|(score, indices)| (score, a.0, indices))
})
}),
);
}).collect::<Vec<(_, _, _)>>();
files.sort_by(|(score1, _, _), (score2, _, _)| score2.cmp(score1));
self.files_filtered.extend(files.into_iter().map(|entry| (entry.1, entry.2)));
}
self.selection = 0;