Skip to content

Commit

Permalink
Distinguish dirs visually in file_browser
Browse files Browse the repository at this point in the history
  • Loading branch information
drybalka committed Oct 4, 2024
1 parent 7e58404 commit adc72f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 8 additions & 8 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ pub fn file_browser(root: PathBuf) -> Result<FilePicker, std::io::Error> {
let columns = [PickerColumn::new(
"path",
|item: &PathBuf, root: &PathBuf| {
item.strip_prefix(root)
.unwrap_or(item)
.to_string_lossy()
.into()
let name = item.strip_prefix(root).unwrap_or(item).to_string_lossy();
if item.is_dir() {
format!("{}/", name).into()
} else {
name.into()
}
},
)];
let picker = Picker::new(
Expand Down Expand Up @@ -316,19 +318,17 @@ fn directory_content(path: &Path) -> Result<Vec<PathBuf>, std::io::Error> {
let mut dirs = Vec::new();
let mut files = Vec::new();
for entry in std::fs::read_dir(path)?.flatten() {
let entry_path = entry.path();
if entry.path().is_dir() {
dirs.push(entry_path);
dirs.push(entry.path());
} else {
files.push(entry_path);
files.push(entry.path());
}
}
dirs.sort();
files.sort();

let mut content = Vec::new();
if path.parent().is_some() {
log::warn!("{}", path.to_string_lossy());
content.insert(0, path.join(".."));
}
content.extend(dirs);
Expand Down
10 changes: 8 additions & 2 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,14 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
let files = super::directory_content(&path)?;
let file_names: Vec<_> = files
.iter()
.filter_map(|file| file.file_name())
.map(|name| name.to_string_lossy().into_owned())
.filter_map(|file| {
let name = file.file_name()?.to_string_lossy();
if file.is_dir() {
Some(format!("{}/", name))
} else {
Some(name.into_owned())
}
})
.collect();
Ok(CachedPreview::Directory(file_names))
} else if metadata.is_file() {
Expand Down

0 comments on commit adc72f2

Please sign in to comment.