Changed startup behaviour to only open a single view when multiple files are specified on the commandline.

Changed the behaviour; the first argument on the commandline is the file on display
This commit is contained in:
Cor 2021-07-14 21:29:39 +02:00 committed by Blaž Hrastnik
parent 000b7b7c97
commit 9fcbbfa467
2 changed files with 8 additions and 1 deletions

View File

@ -83,15 +83,18 @@ pub fn new(args: Args, mut config: Config) -> Result<Self, Error> {
editor.new_file(Action::VerticalSplit); editor.new_file(Action::VerticalSplit);
compositor.push(Box::new(ui::file_picker(first.clone()))); compositor.push(Box::new(ui::file_picker(first.clone())));
} else { } else {
let nr_of_files = args.files.len();
editor.open(first.to_path_buf(), Action::VerticalSplit)?;
for file in args.files { for file in args.files {
if file.is_dir() { if file.is_dir() {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"expected a path to file, found a directory. (to open a directory pass it as first argument)" "expected a path to file, found a directory. (to open a directory pass it as first argument)"
)); ));
} else { } else {
editor.open(file, Action::VerticalSplit)?; editor.open(file.to_path_buf(), Action::Load)?;
} }
} }
editor.set_status(format!("Loaded {} files.", nr_of_files));
} }
} else { } else {
editor.new_file(Action::VerticalSplit); editor.new_file(Action::VerticalSplit);

View File

@ -39,6 +39,7 @@ pub struct Editor {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum Action { pub enum Action {
Load,
Replace, Replace,
HorizontalSplit, HorizontalSplit,
VerticalSplit, VerticalSplit,
@ -151,6 +152,9 @@ pub fn switch(&mut self, id: DocumentId, action: Action) {
return; return;
} }
Action::Load => {
return;
}
Action::HorizontalSplit => { Action::HorizontalSplit => {
let view = View::new(id); let view = View::new(id);
let view_id = self.tree.split(view, Layout::Horizontal); let view_id = self.tree.split(view, Layout::Horizontal);