Skip to content

Commit 638d7c2

Browse files
mark2185extrawurst
andauthored
Sort fuzzy_matcher results based on score (#1183)
Co-authored-by: Stephan D <[email protected]>
1 parent 5f466ff commit 638d7c2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
* tabs indentation in blame [[@fersilva16](https://github.com/fersilva16)] ([#1111](https://github.com/extrawurst/gitui/issues/1117))
2828
* switch focus to index after staging last file ([#1169](https://github.com/extrawurst/gitui/pull/1169))
2929
* fix stashlist multi marking not updated after dropping ([#1207](https://github.com/extrawurst/gitui/pull/1207))
30+
* 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))
3031

3132
## [0.20.1] - 2021-01-26
3233

src/components/file_find_popup.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,18 @@ impl FileFindPopup {
8888
let matcher =
8989
fuzzy_matcher::skim::SkimMatcherV2::default();
9090

91-
self.files_filtered.extend(
91+
let mut files =
9292
self.files.iter().enumerate().filter_map(|a| {
9393
a.1.path.to_str().and_then(|path| {
9494
matcher
9595
.fuzzy_indices(path, q)
96-
.map(|(_, indicies)| (a.0, indicies))
96+
.map(|(score, indices)| (score, a.0, indices))
9797
})
98-
}),
99-
);
98+
}).collect::<Vec<(_, _, _)>>();
99+
100+
files.sort_by(|(score1, _, _), (score2, _, _)| score2.cmp(score1));
101+
102+
self.files_filtered.extend(files.into_iter().map(|entry| (entry.1, entry.2)));
100103
}
101104

102105
self.selection = 0;

0 commit comments

Comments
 (0)