Skip to content

Commit

Permalink
feat: apply natural sort to partitions on both Linux and macOS (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi authored Jan 22, 2025
1 parent 4569356 commit 234809d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion yazi-fs/src/mounts/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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()?;
Expand Down
3 changes: 2 additions & 1 deletion yazi-fs/src/mounts/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 234809d

Please sign in to comment.