on master help sign in
Sort themes, language & files by score & then name (#2675)

* Sort themes by score & then name Previously the themes were appearing unordered after typing ':theme '. This sorts them first by fuzzy score and then by name so that they generally appear in a more ordered fashion in the initial list. The sort by name does not really pay off when there is a score so an alternative approach would be to sort by name if there is string to fuzzy match against and otherwise sort by score. I've lowercased the names as that avoids lower case & upper case letters being sorted into separate groups. There might be a preferable approach to that though. * Sort language & files by score then name And change to use sort_unstable_by instead of sort_unstable_by_key as it allows us to avoid some allocations. I don't fully understand the flow of the 'filename_impl' function but this seems to deliver the desired results. * Remove unnecessary reference Co-authored-by: Michael Davis <mcarsondavis@gmail.com> Co-authored-by: Michael Davis <mcarsondavis@gmail.com>

commitd8abd1eaf398f462122efbc937cda9d8178a5754 authorMichael Jones <m.pricejones@gmail.com> dateFri 1 Jul 2022, 10:33 (4 years ago) parentf10b6f6
1 file changed+12−3
helix-term/src/ui/mod.rs+12−3
helix-term/src/ui/mod.rs+12−3
@@ -257,7 +257,9 @@ pub mod completers {
257257 })
258258 .collect();
259259
260− matches.sort_unstable_by_key(|(_file, score)| Reverse(*score));
260+ matches.sort_unstable_by(|(name1, score1), (name2, score2)| {
261+ (Reverse(*score1), name1).cmp(&(Reverse(*score2), name2))
262+ });
261263 names = matches.into_iter().map(|(name, _)| ((0..), name)).collect();
262264
263265 names
@@ -312,7 +314,9 @@ pub mod completers {
312314 })
313315 .collect();
314316
315− matches.sort_unstable_by_key(|(_language, score)| Reverse(*score));
317+ matches.sort_unstable_by(|(language1, score1), (language2, score2)| {
318+ (Reverse(*score1), language1).cmp(&(Reverse(*score2), language2))
319+ });
316320
317321 matches
318322 .into_iter()
@@ -428,13 +432,18 @@ pub mod completers {
428432
429433 let range = (input.len().saturating_sub(file_name.len()))..;
430434
431− matches.sort_unstable_by_key(|(_file, score)| Reverse(*score));
435+ matches.sort_unstable_by(|(file1, score1), (file2, score2)| {
436+ (Reverse(*score1), file1).cmp(&(Reverse(*score2), file2))
437+ });
438+
432439 files = matches
433440 .into_iter()
434441 .map(|(file, _)| (range.clone(), file))
435442 .collect();
436443
437444 // TODO: complete to longest common match
445+ } else {
446+ files.sort_unstable_by(|(_, path1), (_, path2)| path1.cmp(path2));
438447 }
439448
440449 files