From cbc924f46eb6c42ce9486ad7b051ff79b7df0259 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Tue, 14 Mar 2023 16:19:23 +0100 Subject: [PATCH] sort entries in directory view --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index 76a7063..58e0e0f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use crossterm::{ }, }; use std::{ + cmp::Ordering, env, fs, io::{stdout, Write}, path::PathBuf, @@ -255,6 +256,15 @@ impl Navigator { for file in fs::read_dir(&self.path).unwrap().flatten() { self.files.push(file.path()); } + self.files[1..].sort_unstable_by(|path, other| { + if path.is_dir() == other.is_dir() { + path.cmp(other) + } else if path.is_dir() { + Ordering::Less + } else { + Ordering::Greater + } + }); } fn any_unsaved(&self) -> bool {