@@ -1,10 +1,14 @@
1−use helix_core::{merge_toml_values, syntax};
1+use helix_core::{merge_toml_values, pos_at_coords, syntax, Selection};
22use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
33use helix_view::{theme, Editor};
44use serde_json::json;
55
66use crate::{
7− args::Args, commands::apply_workspace_edit, compositor::Compositor, config::Config, job::Jobs,
7+ args::Args,
8+ commands::{align_view, apply_workspace_edit, Align},
9+ compositor::Compositor,
10+ config::Config,
11+ job::Jobs,
812 ui,
913};
1014
@@ -130,7 +134,7 @@ impl Application {
130134 // Unset path to prevent accidentally saving to the original tutor file.
131135 doc_mut!(editor).set_path(None)?;
132136 } else if !args.files.is_empty() {
133− let first = &args.files[0]; // we know it's not empty
137+ let first = &args.files[0].0; // we know it's not empty
134138 if first.is_dir() {
135139 std::env::set_current_dir(&first)?;
136140 editor.new_file(Action::VerticalSplit);
@@ -138,16 +142,25 @@ impl Application {
138142 } else {
139143 let nr_of_files = args.files.len();
140144 editor.open(first.to_path_buf(), Action::VerticalSplit)?;
141− for file in args.files {
145+ for (file, pos) in args.files {
142146 if file.is_dir() {
143147 return Err(anyhow::anyhow!(
144148 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
145149 ));
146150 } else {
147− editor.open(file.to_path_buf(), Action::Load)?;
151+ let doc_id = editor.open(file, Action::Load)?;
152+ // with Action::Load all documents have the same view
153+ let view_id = editor.tree.focus;
154+ let doc = editor.document_mut(doc_id).unwrap();
155+ let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
156+ doc.set_selection(view_id, pos);
148157 }
149158 }
150159 editor.set_status(format!("Loaded {} files.", nr_of_files));
160+ // align the view to center after all files are loaded,
161+ // does not affect views without pos since it is at the top
162+ let (view, doc) = current!(editor);
163+ align_view(doc, view, Align::Center);
151164 }
152165 } else if stdin().is_tty() {
153166 editor.new_file(Action::VerticalSplit);