@@ -12,7 +12,10 @@ use tui::{
1212use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
1313use tui::widgets::Widget;
1414
15−use std::{cmp::Ordering, time::Instant};
15+use std::{
16+ cmp::{self, Ordering},
17+ time::Instant,
18+};
1619use std::{collections::HashMap, io::Read, path::PathBuf};
1720
1821use crate::ui::{Prompt, PromptEvent};
@@ -344,11 +347,17 @@ impl<T: Item + 'static> Component for FilePicker<T> {
344347
345348#[derive(PartialEq, Eq, Debug)]
346349struct PickerMatch {
347− index: usize,
348350 score: i64,
351+ index: usize,
349352 len: usize,
350353}
351354
355+impl PickerMatch {
356+ fn key(&self) -> impl Ord {
357+ (cmp::Reverse(self.score), self.len, self.index)
358+ }
359+}
360+
352361impl PartialOrd for PickerMatch {
353362 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
354363 Some(self.cmp(other))
@@ -357,10 +366,7 @@ impl PartialOrd for PickerMatch {
357366
358367impl Ord for PickerMatch {
359368 fn cmp(&self, other: &Self) -> Ordering {
360− self.score
361− .cmp(&other.score)
362− .reverse()
363− .then_with(|| self.len.cmp(&other.len))
369+ self.key().cmp(&other.key())
364370 }
365371}
366372
@@ -502,6 +508,7 @@ impl<T: Item> Picker<T> {
502508 })
503509 }),
504510 );
511+
505512 self.matches.sort_unstable();
506513 }
507514