on master help sign in
Fixed issue when the first file specified as an argument was a relative directory (#8520)
e6d2835Bjorn Ove Hay Andersen
helix-term/src/application.rs+1−2
@@ -162,8 +162,7 @@ impl Application {
162 // Unset path to prevent accidentally saving to the original tutor file.
162 // Unset path to prevent accidentally saving to the original tutor file.
163 doc_mut!(editor).set_path(None);
163 doc_mut!(editor).set_path(None);
164 } else if !args.files.is_empty() {
164 } else if !args.files.is_empty() {
165− let first = &args.files[0].0; // we know it's not empty
165+ if args.open_cwd {
166− if first.is_dir() {
167 // NOTE: The working directory is already set to args.files[0] in main()
166 // NOTE: The working directory is already set to args.files[0] in main()
168 editor.new_file(Action::VerticalSplit);
167 editor.new_file(Action::VerticalSplit);
169 let picker = ui::file_picker(".".into(), &config.load().editor);
168 let picker = ui::file_picker(".".into(), &config.load().editor);
helix-term/src/args.rs+1
@@ -17,6 +17,7 @@ pub struct Args {
17 pub log_file: Option<PathBuf>,
17 pub log_file: Option<PathBuf>,
18 pub config_file: Option<PathBuf>,
18 pub config_file: Option<PathBuf>,
19 pub files: Vec<(PathBuf, Position)>,
19 pub files: Vec<(PathBuf, Position)>,
20+ pub open_cwd: bool,
20 pub working_directory: Option<PathBuf>,
21 pub working_directory: Option<PathBuf>,
21}
22}
22
23
helix-term/src/main.rs+7−3
@@ -76,7 +76,7 @@ FLAGS:
76 helix_loader::default_log_file().display(),
76 helix_loader::default_log_file().display(),
77 );
77 );
78
78
79− let args = Args::parse_args().context("could not parse arguments")?;
79+ let mut args = Args::parse_args().context("could not parse arguments")?;
80
80
81 helix_loader::initialize_config_file(args.config_file.clone());
81 helix_loader::initialize_config_file(args.config_file.clone());
82 helix_loader::initialize_log_file(args.log_file.clone());
82 helix_loader::initialize_log_file(args.log_file.clone());
@@ -118,10 +118,14 @@ FLAGS:
118
118
119 // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
119 // NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
120 // Application::new() depends on this logic so it must be updated if this changes.
120 // 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 {
122 helix_loader::set_current_working_dir(path)?;
122 helix_loader::set_current_working_dir(path)?;
123+ }
124+
125+ // If the first file is a directory, it will be the working directory and a file picker will be opened
123− } else if let Some(path) = &args.working_directory {
126+ if let Some((path, _)) = args.files.first().filter(|p| p.0.is_dir()) {
124 helix_loader::set_current_working_dir(path)?;
127 helix_loader::set_current_working_dir(path)?;
128+ args.open_cwd = true; // Signal Application that we want to open the picker on "."
125 }
129 }
126
130
127 let config = match Config::load_default() {
131 let config = match Config::load_default() {
helix-term/tests/test/helpers.rs+8
@@ -320,6 +320,14 @@ impl AppBuilder {
320 }
320 }
321
321
322 pub fn build(self) -> anyhow::Result<Application> {
322 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+
323 let mut app = Application::new(self.args, self.config, self.syn_conf)?;
331 let mut app = Application::new(self.args, self.config, self.syn_conf)?;
324
332
325 if let Some((text, selection)) = self.input {
333 if let Some((text, selection)) = self.input {