Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--helix-term/src/application.rs2
-rw-r--r--helix-term/src/commands.rs10
-rw-r--r--helix-term/src/commands/typed.rs2
-rw-r--r--helix-term/src/ui/mod.rs39
4 files changed, 37 insertions, 16 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 499732f0..1da2a700 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -157,7 +157,7 @@ impl Application {
// If the first file is a directory, skip it and open a picker
if let Some((first, _)) = files_it.next_if(|(p, _)| p.is_dir()) {
- let picker = ui::file_picker(first, &config.load().editor);
+ let picker = ui::file_picker(&editor, first);
compositor.push(Box::new(overlaid(picker)));
}
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 1fb27a39..a95e2a90 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1344,7 +1344,7 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
let path = path::expand(&sel);
let path = &rel_path.join(path);
if path.is_dir() {
- let picker = ui::file_picker(path.into(), &cx.editor.config());
+ let picker = ui::file_picker(cx.editor, path.into());
cx.push_layer(Box::new(overlaid(picker)));
} else if let Err(e) = cx.editor.open(path, action) {
cx.editor.set_error(format!("Open file failed: {:?}", e));
@@ -1381,7 +1381,7 @@ fn open_url(cx: &mut Context, url: Url, action: Action) {
Ok(_) | Err(_) => {
let path = &rel_path.join(url.path());
if path.is_dir() {
- let picker = ui::file_picker(path.into(), &cx.editor.config());
+ let picker = ui::file_picker(cx.editor, path.into());
cx.push_layer(Box::new(overlaid(picker)));
} else if let Err(e) = cx.editor.open(path, action) {
cx.editor.set_error(format!("Open file failed: {:?}", e));
@@ -3001,7 +3001,7 @@ fn file_picker(cx: &mut Context) {
cx.editor.set_error("Workspace directory does not exist");
return;
}
- let picker = ui::file_picker(root, &cx.editor.config());
+ let picker = ui::file_picker(cx.editor, root);
cx.push_layer(Box::new(overlaid(picker)));
}
@@ -3018,7 +3018,7 @@ fn file_picker_in_current_buffer_directory(cx: &mut Context) {
}
};
- let picker = ui::file_picker(path, &cx.editor.config());
+ let picker = ui::file_picker(cx.editor, path);
cx.push_layer(Box::new(overlaid(picker)));
}
@@ -3029,7 +3029,7 @@ fn file_picker_in_current_directory(cx: &mut Context) {
.set_error("Current working directory does not exist");
return;
}
- let picker = ui::file_picker(cwd, &cx.editor.config());
+ let picker = ui::file_picker(cx.editor, cwd);
cx.push_layer(Box::new(overlaid(picker)));
}
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 7ec59487..3953457c 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -119,7 +119,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
let callback = async move {
let call: job::Callback = job::Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, compositor: &mut Compositor| {
- let picker = ui::file_picker(path.into_owned(), &editor.config());
+ let picker = ui::file_picker(editor, path.into_owned());
compositor.push(Box::new(overlaid(picker)));
},
));
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 21a68d7f..a76adbe2 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -30,7 +30,7 @@ pub use spinner::{ProgressSpinners, Spinner};
pub use text::Text;
use helix_view::Editor;
-use tui::text::Span;
+use tui::text::{Span, Spans};
use std::path::Path;
use std::{error::Error, path::PathBuf};
@@ -185,12 +185,23 @@ pub fn raw_regex_prompt(
cx.push_layer(Box::new(prompt));
}
-type FilePicker = Picker<PathBuf, PathBuf>;
+#[derive(Debug)]
+pub struct FilePickerData {
+ root: PathBuf,
+ directory_style: Style,
+}
+type FilePicker = Picker<PathBuf, FilePickerData>;
-pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker {
+pub fn file_picker(editor: &Editor, root: PathBuf) -> FilePicker {
use ignore::{types::TypesBuilder, WalkBuilder};
use std::time::Instant;
+ let config = editor.config();
+ let data = FilePickerData {
+ root: root.clone(),
+ directory_style: editor.theme.get("ui.text.directory"),
+ };
+
let now = Instant::now();
let dedup_symlinks = config.file_picker.deduplicate_links;
@@ -236,14 +247,24 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
let columns = [PickerColumn::new(
"path",
- |item: &PathBuf, root: &PathBuf| {
- item.strip_prefix(root)
- .unwrap_or(item)
- .to_string_lossy()
- .into()
+ |item: &PathBuf, data: &FilePickerData| {
+ let path = item.strip_prefix(&data.root).unwrap_or(item);
+ let mut spans = Vec::with_capacity(3);
+ if let Some(dirs) = path.parent().filter(|p| !p.as_os_str().is_empty()) {
+ spans.extend([
+ Span::styled(dirs.to_string_lossy(), data.directory_style),
+ Span::styled(std::path::MAIN_SEPARATOR_STR, data.directory_style),
+ ]);
+ }
+ let filename = path
+ .file_name()
+ .expect("normalized paths can't end in `..`")
+ .to_string_lossy();
+ spans.push(Span::raw(filename));
+ Spans::from(spans).into()
},
)];
- let picker = Picker::new(columns, 0, [], root, move |cx, path: &PathBuf, action| {
+ let picker = Picker::new(columns, 0, [], data, move |cx, path: &PathBuf, action| {
if let Err(e) = cx.editor.open(path, action) {
let err = if let Some(err) = e.source() {
format!("{}", err)