Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with opening a relative directory with hx <dir> introduced in #8498 #8520

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub open_cwd: bool,
pub working_directory: Option<PathBuf>,
}

Expand Down
10 changes: 7 additions & 3 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions helix-term/tests/test/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ impl AppBuilder {
}

pub fn build(self) -> anyhow::Result<Application> {
if let Some(path) = &self.args.working_directory {
bail!("Changing the working directory to {path:?} is not yet supported for integration tests");
}

if let Some((path, _)) = self.args.files.first().filter(|p| p.0.is_dir()) {
bail!("Having the directory {path:?} in args.files[0] is not yet supported for integration tests");
}

let mut app = Application::new(self.args, self.config, self.syn_conf)?;

if let Some((text, selection)) = self.input {
Expand Down
Loading