diff --git a/README.md b/README.md index 80442695..5eb2dc9c 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ and removes duplicate hardlinks. Press `v` (or click **Volumes** beside the disk name in the side panel) to bring up the volume picker. It lists every candidate volume mounted on the -system together with its free space, ordered fullest first, filtering out +system together with its free space, by name, filtering out pseudo-filesystems and duplicate btrfs/APFS mount points. Selecting any entry resets the scan root directly to that volume. diff --git a/crates/disktree-app/src/state.rs b/crates/disktree-app/src/state.rs index ee351f3a..64df337d 100644 --- a/crates/disktree-app/src/state.rs +++ b/crates/disktree-app/src/state.rs @@ -672,6 +672,7 @@ impl Disktree { }); } volumes.retain(|volume| volume.point != root_path); + by_name(&mut volumes); volumes }); cx.spawn(async move |this, cx| { @@ -3147,6 +3148,16 @@ pub fn now_seconds() -> i64 { }) } +/// Order the picker's volumes by name, as a file manager lists drives: a +/// volume is found where its letter or name says, however full it happens +/// to be. Without regard to case, so `/Volumes/archive` is not sent below +/// every capital. +pub fn by_name(volumes: &mut [disktree_core::space::Volume]) { + volumes.sort_by_cached_key(|volume| { + volume.point.to_string_lossy().to_lowercase() + }); +} + /// Let go of a tree off the UI thread: freeing a disk's millions of nodes /// takes a good part of a second, and nothing waits on it. fn discard(tree: Option>) { diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs index 3d7f151b..b5e7728b 100644 --- a/crates/disktree-app/src/tests.rs +++ b/crates/disktree-app/src/tests.rs @@ -1844,3 +1844,19 @@ fn the_power_menu_offers_only_what_the_cpus_can_tell_apart( draw(cx); assert!(read(&view, cx, |app| app.power_menu.is_none())); } + +#[test] +fn the_volume_picker_lists_volumes_by_name() { + let volume = |point: &str| Volume { + point: PathBuf::from(point), + device: None, + space: None, + }; + let mut volumes = vec![volume("E:\\"), volume("c:\\"), volume("D:\\")]; + crate::state::by_name(&mut volumes); + let order: Vec<_> = volumes + .iter() + .map(|volume| volume.point.to_string_lossy().into_owned()) + .collect(); + assert_eq!(order, ["c:\\", "D:\\", "E:\\"]); +}