mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-27 10:22:40 +00:00
Add case-insensitive extension sorting
This finishes off and closes #102. The code in this and the previous commit were partly authored by `zv0n` on GitHub.
This commit is contained in:
parent
3e9616cffa
commit
8805ce9e3b
@ -367,17 +367,25 @@ impl FileFilter {
|
|||||||
|
|
||||||
match self.sort_field {
|
match self.sort_field {
|
||||||
SortField::Unsorted => cmp::Ordering::Equal,
|
SortField::Unsorted => cmp::Ordering::Equal,
|
||||||
|
|
||||||
SortField::Name(Sensitive) => natord::compare(&a.name, &b.name),
|
SortField::Name(Sensitive) => natord::compare(&a.name, &b.name),
|
||||||
SortField::Name(Insensitive) => natord::compare_ignore_case(&a.name, &b.name),
|
SortField::Name(Insensitive) => natord::compare_ignore_case(&a.name, &b.name),
|
||||||
|
|
||||||
SortField::Size => a.metadata.len().cmp(&b.metadata.len()),
|
SortField::Size => a.metadata.len().cmp(&b.metadata.len()),
|
||||||
SortField::FileInode => a.metadata.ino().cmp(&b.metadata.ino()),
|
SortField::FileInode => a.metadata.ino().cmp(&b.metadata.ino()),
|
||||||
SortField::ModifiedDate => a.metadata.mtime().cmp(&b.metadata.mtime()),
|
SortField::ModifiedDate => a.metadata.mtime().cmp(&b.metadata.mtime()),
|
||||||
SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()),
|
SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()),
|
||||||
SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()),
|
SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()),
|
||||||
SortField::Extension => match a.ext.cmp(&b.ext) {
|
|
||||||
|
SortField::Extension(Sensitive) => match a.ext.cmp(&b.ext) {
|
||||||
cmp::Ordering::Equal => natord::compare(&*a.name, &*b.name),
|
cmp::Ordering::Equal => natord::compare(&*a.name, &*b.name),
|
||||||
order => order,
|
order => order,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
SortField::Extension(Insensitive) => match a.ext.cmp(&b.ext) {
|
||||||
|
cmp::Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name),
|
||||||
|
order => order,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,7 +470,9 @@ impl RecurseOptions {
|
|||||||
/// User-supplied field to sort by.
|
/// User-supplied field to sort by.
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
pub enum SortField {
|
pub enum SortField {
|
||||||
Unsorted, Name(SortCase), Extension, Size, FileInode,
|
Unsorted,
|
||||||
|
Name(SortCase), Extension(SortCase),
|
||||||
|
Size, FileInode,
|
||||||
ModifiedDate, AccessedDate, CreatedDate,
|
ModifiedDate, AccessedDate, CreatedDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +498,8 @@ impl OptionSet for SortField {
|
|||||||
"name" | "filename" => Ok(SortField::Name(SortCase::Sensitive)),
|
"name" | "filename" => Ok(SortField::Name(SortCase::Sensitive)),
|
||||||
"Name" | "Filename" => Ok(SortField::Name(SortCase::Insensitive)),
|
"Name" | "Filename" => Ok(SortField::Name(SortCase::Insensitive)),
|
||||||
"size" | "filesize" => Ok(SortField::Size),
|
"size" | "filesize" => Ok(SortField::Size),
|
||||||
"ext" | "extension" => Ok(SortField::Extension),
|
"ext" | "extension" => Ok(SortField::Extension(SortCase::Sensitive)),
|
||||||
|
"Ext" | "Extension" => Ok(SortField::Extension(SortCase::Insensitive)),
|
||||||
"mod" | "modified" => Ok(SortField::ModifiedDate),
|
"mod" | "modified" => Ok(SortField::ModifiedDate),
|
||||||
"acc" | "accessed" => Ok(SortField::AccessedDate),
|
"acc" | "accessed" => Ok(SortField::AccessedDate),
|
||||||
"cr" | "created" => Ok(SortField::CreatedDate),
|
"cr" | "created" => Ok(SortField::CreatedDate),
|
||||||
|
Loading…
Reference in New Issue
Block a user