Skip to content

Commit

Permalink
Sort fuzzy_matcher results based on score
Browse files Browse the repository at this point in the history
  • Loading branch information
mark2185 committed Apr 8, 2022
1 parent 505e016 commit c75f105
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* opening tags list without remotes ([#1111](https://github.com/extrawurst/gitui/1111))
* 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/1169))
* 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/1183))

## [0.20.1] - 2021-01-26

Expand Down
11 changes: 7 additions & 4 deletions src/components/file_find_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c75f105

Please sign in to comment.