@@ -1,5 +1,5 @@
11use helix_core::{
2− comment, coords_at_pos, graphemes, indent, match_brackets,
2+ comment, coords_at_pos, find_root, graphemes, indent, match_brackets,
33 movement::{self, Direction},
44 object, pos_at_coords,
55 regex::{self, Regex},
@@ -1093,30 +1093,6 @@ pub fn command_mode(cx: &mut Context) {
10931093 cx.push_layer(Box::new(prompt));
10941094}
10951095
1096−fn find_root(root: Option<&str>) -> Option<PathBuf> {
1097− let current_dir = std::env::current_dir().expect("unable to determine current directory");
1098−
1099− let root = match root {
1100− Some(root) => {
1101− let root = Path::new(root);
1102− if root.is_absolute() {
1103− root.to_path_buf()
1104− } else {
1105− current_dir.join(root)
1106− }
1107− }
1108− None => current_dir,
1109− };
1110−
1111− for ancestor in root.ancestors() {
1112− // TODO: also use defined roots if git isn't found
1113− if ancestor.join(".git").is_dir() {
1114− return Some(ancestor.to_path_buf());
1115− }
1116− }
1117− None
1118−}
1119−
11201096pub fn file_picker(cx: &mut Context) {
11211097 let root = find_root(None).unwrap_or_else(|| PathBuf::from("./"));
11221098 let picker = ui::file_picker(root);