@@ -14,7 +14,7 @@ use crate::{
14 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
14 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
17−use std::path::PathBuf;
17+use std::path::{Path, PathBuf};
19use helix_view::{
19use helix_view::{
20 document::Mode,
20 document::Mode,
@@ -840,8 +840,34 @@ pub fn command_mode(cx: &mut Context) {
841 cx.push_layer(Box::new(prompt));
841 cx.push_layer(Box::new(prompt));
844+fn find_root(root: Option<&str>) -> Option<PathBuf> {
845+ let current_dir = std::env::current_dir().expect("unable to determine current directory");
847+ let root = match root {
849+ let root = Path::new(root);
850+ if root.is_absolute() {
853+ current_dir.join(root)
856+ None => current_dir,
859+ for ancestor in root.ancestors() {
860+ // TODO: also use defined roots if git isn't found
861+ if ancestor.join(".git").is_dir() {
862+ return Some(ancestor.to_path_buf());
843pub fn file_picker(cx: &mut Context) {
868pub fn file_picker(cx: &mut Context) {
869+ let root = find_root(None).unwrap_or_else(|| PathBuf::from("./"));
844− let picker = ui::file_picker("./");
870+ let picker = ui::file_picker(root);
845 cx.push_layer(Box::new(picker));
871 cx.push_layer(Box::new(picker));