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

feat: open file picker on directories using goto_file (gf) #7909

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Changes from 1 commit
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
24 changes: 16 additions & 8 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,13 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
for sel in paths {
let p = sel.trim();
if !p.is_empty() {
if let Err(e) = cx.editor.open(&PathBuf::from(p), action) {
cx.editor.set_error(format!("Open file failed: {:?}", e));
let path = Path::new(p);
if let Ok(path) = helix_core::path::get_canonicalized_path(path) {
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
if path.is_dir() {
file_picker_in(cx, path);
} else if let Err(e) = cx.editor.open(&path, action) {
cx.editor.set_error(format!("Open file failed: {:?}", e));
}
}
}
}
Expand Down Expand Up @@ -2561,14 +2566,18 @@ fn append_mode(cx: &mut Context) {
doc.set_selection(view.id, selection);
}

fn file_picker_in(cx: &mut Context, root: PathBuf) {
let picker = ui::file_picker(root, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
}

the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
fn file_picker(cx: &mut Context) {
let root = find_workspace().0;
if !root.exists() {
cx.editor.set_error("Workspace directory does not exist");
return;
}
let picker = ui::file_picker(root, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
file_picker_in(cx, root)
}

fn file_picker_in_current_buffer_directory(cx: &mut Context) {
Expand All @@ -2584,18 +2593,17 @@ fn file_picker_in_current_buffer_directory(cx: &mut Context) {
}
};

let picker = ui::file_picker(path, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
file_picker_in(cx, path)
}

fn file_picker_in_current_directory(cx: &mut Context) {
let cwd = helix_loader::current_working_dir();
if !cwd.exists() {
cx.editor
.set_error("Current working directory does not exist");
return;
}
let picker = ui::file_picker(cwd, &cx.editor.config());
cx.push_layer(Box::new(overlaid(picker)));
file_picker_in(cx, cwd)
}

fn buffer_picker(cx: &mut Context) {
Expand Down