Skip to content

Commit

Permalink
Bette sorting in picker in case of ties
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Dec 15, 2022
1 parent ec9aa66 commit d2d7a09
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,7 @@ impl<T: Item> Picker<T> {
None => false,
}
});

self.matches.sort_unstable();
self.sort_matches();
} else {
self.force_score();
}
Expand Down Expand Up @@ -502,7 +501,20 @@ impl<T: Item> Picker<T> {
})
}),
);
self.matches.sort_unstable();
self.sort_matches();
}

/// Sort matches by (score, text).
fn sort_matches(&mut self) {
self.matches.sort_unstable_by(|l, r| {
l.cmp(r).then_with(|| {
let l_option = &self.options[l.index];
let l_text = l_option.filter_text(&self.editor_data);
let r_option = &self.options[r.index];
let r_text = r_option.filter_text(&self.editor_data);
l_text.cmp(&r_text)
})
});
}

/// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
Expand Down

0 comments on commit d2d7a09

Please sign in to comment.