on master help sign in
Fixed issue when the first file specified as an argument was a relative directory (#8520)
commite6d2835b0907102831a8979688a8464c064ff842 authorBjorn Ove Hay Andersen <bjrnove@gmail.com> dateWed 18 Oct 2023, 10:45 (3 years ago) parentfc16449
4 files changed+17−5
helix-term/src/application.rs+1−2 helix-term/src/args.rs+1 helix-term/src/main.rs+7−3 helix-term/tests/test/helpers.rs+8
helix-term/src/application.rs+1−2
@@ -162,8 +162,7 @@ impl Application {
162162 // Unset path to prevent accidentally saving to the original tutor file.
163163 doc_mut!(editor).set_path(None);
164164 } else if !args.files.is_empty() {
165− let first = &args.files[0].0; // we know it's not empty
166− if first.is_dir() {
165+ if args.open_cwd {
167166 // NOTE: The working directory is already set to args.files[0] in main()
168167 editor.new_file(Action::VerticalSplit);
169168 let picker = ui::file_picker(".".into(), &config.load().editor);
helix-term/src/args.rs+1
@@ -17,6 +17,7 @@ pub struct Args {
1717 pub log_file: Option<PathBuf>,
1818 pub config_file: Option<PathBuf>,
1919 pub files: Vec<(PathBuf, Position)>,
20+ pub open_cwd: bool,
2021 pub working_directory: Option<PathBuf>,
2122}
2223
helix-term/src/main.rs+7−3
@@ -76,7 +76,7 @@ FLAGS:
7676 helix_loader::default_log_file().display(),
7777 );
7878
79− let args = Args::parse_args().context("could not parse arguments")?;
79+ let mut args = Args::parse_args().context("could not parse arguments")?;
8080
8181 helix_loader::initialize_config_file(args.config_file.clone());
8282 helix_loader::initialize_log_file(args.log_file.clone());
@@ -118,10 +118,14 @@ FLAGS:
118118
119119 // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
120120 // Application::new() depends on this logic so it must be updated if this changes.
121− if let Some((path, true)) = args.files.first().map(|(path, _)| (path, path.is_dir())) {
121+ if let Some(path) = &args.working_directory {
122122 helix_loader::set_current_working_dir(path)?;
123− } else if let Some(path) = &args.working_directory {
123+ }
124+
125+ // If the first file is a directory, it will be the working directory and a file picker will be opened
126+ if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) {
124127 helix_loader::set_current_working_dir(path)?;
128+ args.open_cwd = true; // Signal Application that we want to open the picker on "."
125129 }
126130
127131 let config = match Config::load_default() {
helix-term/tests/test/helpers.rs+8
@@ -320,6 +320,14 @@ impl AppBuilder {
320320 }
321321
322322 pub fn build(self) -> anyhow::Result<Application> {
323+ if let Some(path) = &self.args.working_directory {
324+ bail!("Changing the working directory to {path:?} is not yet supported for integration tests");
325+ }
326+
327+ if let Some((path, _)) = self.args.files.first().filter(|p| p.0.is_dir()) {
328+ bail!("Having the directory {path:?} in args.files[0] is not yet supported for integration tests");
329+ }
330+
323331 let mut app = Application::new(self.args, self.config, self.syn_conf)?;
324332
325333 if let Some((text, selection)) = self.input {