mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-09-11 16:07:00 +03:00
Better sorting in picker in case of ties (#5169)
This commit is contained in:
parent
b12c65678a
commit
e6a2df8c79
@ -207,13 +207,14 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
|
||||
|
||||
// Cap the number of files if we aren't in a git project, preventing
|
||||
// hangs when using the picker in your home directory
|
||||
let files: Vec<_> = if root.join(".git").exists() {
|
||||
let mut files: Vec<PathBuf> = if root.join(".git").exists() {
|
||||
files.collect()
|
||||
} else {
|
||||
// const MAX: usize = 8192;
|
||||
const MAX: usize = 100_000;
|
||||
files.take(MAX).collect()
|
||||
};
|
||||
files.sort();
|
||||
|
||||
log::debug!("file_picker init {:?}", Instant::now().duration_since(now));
|
||||
|
||||
|
@ -12,7 +12,10 @@
|
||||
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
|
||||
use tui::widgets::Widget;
|
||||
|
||||
use std::{cmp::Ordering, time::Instant};
|
||||
use std::{
|
||||
cmp::{self, Ordering},
|
||||
time::Instant,
|
||||
};
|
||||
use std::{collections::HashMap, io::Read, path::PathBuf};
|
||||
|
||||
use crate::ui::{Prompt, PromptEvent};
|
||||
@ -344,11 +347,17 @@ fn required_size(&mut self, (width, height): (u16, u16)) -> Option<(u16, u16)> {
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
struct PickerMatch {
|
||||
index: usize,
|
||||
score: i64,
|
||||
index: usize,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl PickerMatch {
|
||||
fn key(&self) -> impl Ord {
|
||||
(cmp::Reverse(self.score), self.len, self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for PickerMatch {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@ -357,10 +366,7 @@ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
|
||||
impl Ord for PickerMatch {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.score
|
||||
.cmp(&other.score)
|
||||
.reverse()
|
||||
.then_with(|| self.len.cmp(&other.len))
|
||||
self.key().cmp(&other.key())
|
||||
}
|
||||
}
|
||||
|
||||
@ -502,6 +508,7 @@ pub fn force_score(&mut self) {
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
self.matches.sort_unstable();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user