@@ -5,7 +5,7 @@ use helix_core::{
55 pos_at_coords, syntax, Selection,
66};
77use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
8−use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
8+use helix_view::{align_view, editor::ConfigEvent, theme, tree::Layout, Align, Editor};
99use serde_json::json;
1010
1111use crate::{
@@ -158,16 +158,31 @@ impl Application {
158158 } else {
159159 let nr_of_files = args.files.len();
160160 editor.open(first, Action::VerticalSplit)?;
161− for (file, pos) in args.files {
161+ // Because the line above already opens the first file, we can
162+ // simply skip opening it a second time by using .skip(1) here.
163+ for (file, pos) in args.files.into_iter().skip(1) {
162164 if file.is_dir() {
163165 return Err(anyhow::anyhow!(
164166 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
165167 ));
166168 } else {
169+ // If the user passes in either `--vsplit` or
170+ // `--hsplit` as a command line argument, all the given
171+ // files will be opened according to the selected
172+ // option. If neither of those two arguments are passed
173+ // in, just load the files normally.
174+ let action = match args.split {
175+ Some(Layout::Vertical) => Action::VerticalSplit,
176+ Some(Layout::Horizontal) => Action::HorizontalSplit,
177+ None => Action::Load,
178+ };
167179 let doc_id = editor
168− .open(&file, Action::Load)
180+ .open(&file, action)
169181 .context(format!("open '{}'", file.to_string_lossy()))?;
170182 // with Action::Load all documents have the same view
183+ // NOTE: this isn't necessarily true anymore. If
184+ // `--vsplit` or `--hsplit` are used, the file which is
185+ // opened last is focused on.
171186 let view_id = editor.tree.focus;
172187 let doc = editor.document_mut(doc_id).unwrap();
173188 let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));