on master help sign in
Show file picker when directory passed as first arg
43b92b2wojciechkepka
helix-term/src/application.rs+16−4
@@ -45,16 +45,28 @@ impl Application {
45 let size = compositor.size();
45 let size = compositor.size();
46 let mut editor = Editor::new(size);
46 let mut editor = Editor::new(size);
47
47
48+ compositor.push(Box::new(ui::EditorView::new()));
49+
48 if !args.files.is_empty() {
50 if !args.files.is_empty() {
51+ let first = &args.files[0]; // we know it's not empty
52+ if first.is_dir() {
53+ editor.new_file(Action::VerticalSplit);
54+ compositor.push(Box::new(ui::file_picker(first.clone())));
55+ } else {
49− for file in args.files {
56+ for file in args.files {
57+ if file.is_dir() {
58+ return Err(anyhow::anyhow!(
59+ "expected a path to file, found a directory. (to open a directory pass it as first argument)"
60+ ));
61+ } else {
50− editor.open(file, Action::VerticalSplit)?;
62+ editor.open(file, Action::VerticalSplit)?;
63+ }
64+ }
51 }
65 }
52 } else {
66 } else {
53 editor.new_file(Action::VerticalSplit);
67 editor.new_file(Action::VerticalSplit);
54 }
68 }
55
69
56− compositor.push(Box::new(ui::EditorView::new()));
57−
58 let mut app = Self {
70 let mut app = Self {
59 compositor,
71 compositor,
60 editor,
72 editor,