From e6d2835b0907102831a8979688a8464c064ff842 Mon Sep 17 00:00:00 2001 From: Bjorn Ove Hay Andersen Date: Wed, 18 Oct 2023 10:45:05 +0200 Subject: Fixed issue when the first file specified as an argument was a relative directory (#8520) --- helix-term/src/application.rs | 3 +-- helix-term/src/args.rs | 1 + helix-term/src/main.rs | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index fabd0fa4..43e1cdfc 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -162,8 +162,7 @@ impl Application { // Unset path to prevent accidentally saving to the original tutor file. doc_mut!(editor).set_path(None); } else if !args.files.is_empty() { - let first = &args.files[0].0; // we know it's not empty - if first.is_dir() { + if args.open_cwd { // NOTE: The working directory is already set to args.files[0] in main() editor.new_file(Action::VerticalSplit); let picker = ui::file_picker(".".into(), &config.load().editor); diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index 6a49889b..99ce3992 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -17,6 +17,7 @@ pub struct Args { pub log_file: Option, pub config_file: Option, pub files: Vec<(PathBuf, Position)>, + pub open_cwd: bool, pub working_directory: Option, } diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs index 8db5f310..6411a7c5 100644 --- a/helix-term/src/main.rs +++ b/helix-term/src/main.rs @@ -76,7 +76,7 @@ FLAGS: helix_loader::default_log_file().display(), ); - let args = Args::parse_args().context("could not parse arguments")?; + let mut args = Args::parse_args().context("could not parse arguments")?; helix_loader::initialize_config_file(args.config_file.clone()); helix_loader::initialize_log_file(args.log_file.clone()); @@ -118,10 +118,14 @@ FLAGS: // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that // Application::new() depends on this logic so it must be updated if this changes. - if let Some((path, true)) = args.files.first().map(|(path, _)| (path, path.is_dir())) { + if let Some(path) = &args.working_directory { helix_loader::set_current_working_dir(path)?; - } else if let Some(path) = &args.working_directory { + } + + // If the first file is a directory, it will be the working directory and a file picker will be opened + if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) { helix_loader::set_current_working_dir(path)?; + args.open_cwd = true; // Signal Application that we want to open the picker on "." } let config = match Config::load_default() { -- cgit v1.2.3-70-g09d2