feat: apply natural sort to partitions on both Linux and macOS

This commit is contained in:
sxyazi 2025-01-22 21:55:46 +08:00
parent 456935658a
commit 5775f0ed80
No known key found for this signature in database
2 changed files with 4 additions and 2 deletions

View file

@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString},
use anyhow::Result;
use tokio::{io::{Interest, unix::AsyncFd}, time::sleep};
use tracing::error;
use yazi_shared::{replace_cow, replace_vec_cow};
use yazi_shared::{natsort, replace_cow, replace_vec_cow};
use super::{Locked, Partition, Partitions};
@ -77,6 +77,7 @@ impl Partitions {
let mut set: HashSet<&OsStr> = set.iter().map(AsRef::as_ref).collect();
mounts.iter().filter_map(|p| p.dev_name()).for_each(|s| _ = set.remove(s));
mounts.extend(set.into_iter().map(Partition::new));
mounts.sort_unstable_by(|a, b| natsort(a.src.as_bytes(), b.src.as_bytes(), false));
};
let labels = Self::labels()?;

View file

@ -7,6 +7,7 @@ use objc::{msg_send, runtime::Object, sel, sel_impl};
use scopeguard::defer;
use tracing::error;
use yazi_ffi::{CFDict, CFString, DADiskCopyDescription, DADiskCreateFromBSDName, DARegisterDiskAppearedCallback, DARegisterDiskDescriptionChangedCallback, DARegisterDiskDisappearedCallback, DASessionCreate, DASessionScheduleWithRunLoop, IOIteratorNext, IOObjectRelease, IORegistryEntryCreateCFProperty, IOServiceGetMatchingServices, IOServiceMatching};
use yazi_shared::natsort;
use super::{Locked, Partition, Partitions};
@ -145,7 +146,7 @@ impl Partitions {
}
}
names.sort_unstable();
names.sort_unstable_by(|a, b| natsort(a.as_bytes(), b.as_bytes(), false));
Ok(names)
}