@@ -14,7 +14,7 @@ use crate::{
1414 ui::{self, Completion, Picker, Popup, Prompt, PromptEvent},
1515};
1616
17−use std::path::PathBuf;
17+use std::path::{Path, PathBuf};
1818
1919use helix_view::{
2020 document::Mode,
@@ -840,8 +840,34 @@ pub fn command_mode(cx: &mut Context) {
840840 );
841841 cx.push_layer(Box::new(prompt));
842842}
843+
844+fn find_root(root: Option<&str>) -> Option<PathBuf> {
845+ let current_dir = std::env::current_dir().expect("unable to determine current directory");
846+
847+ let root = match root {
848+ Some(root) => {
849+ let root = Path::new(root);
850+ if root.is_absolute() {
851+ root.to_path_buf()
852+ } else {
853+ current_dir.join(root)
854+ }
855+ }
856+ None => current_dir,
857+ };
858+
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());
863+ }
864+ }
865+ None
866+}
867+
843868pub fn file_picker(cx: &mut Context) {
844− let picker = ui::file_picker("./");
869+ let root = find_root(None).unwrap_or_else(|| PathBuf::from("./"));
870+ let picker = ui::file_picker(root);
845871 cx.push_layer(Box::new(picker));
846872}
847873