From e833d65b77211c76cd1eef1ac723efb3f61d38ba Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 29 Mar 2021 17:04:12 +0900 Subject: Teach file picker how to find the project root (.git). --- helix-term/src/ui/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'helix-term/src/ui/mod.rs') diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 0e38e598..47c75d2f 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -79,10 +79,9 @@ pub fn regex_prompt( ) } -pub fn file_picker(root: &str) -> Picker { +pub fn file_picker(root: PathBuf) -> Picker { use ignore::Walk; - // TODO: determine root based on git root - let files = Walk::new(root).filter_map(|entry| match entry { + let files = Walk::new(root.clone()).filter_map(|entry| match entry { Ok(entry) => { // filter dirs, but we might need special handling for symlinks! if !entry.file_type().unwrap().is_dir() { @@ -96,12 +95,11 @@ pub fn file_picker(root: &str) -> Picker { const MAX: usize = 1024; - use helix_view::Editor; Picker::new( files.take(MAX).collect(), - |path: &PathBuf| { + move |path: &PathBuf| { // format_fn - path.strip_prefix("./").unwrap().to_str().unwrap().into() + path.strip_prefix(&root).unwrap().to_str().unwrap().into() }, move |editor: &mut Editor, path: &PathBuf, action| { let document_id = editor -- cgit v1.2.3-70-g09d2