Open file browser in buffer's directory

pull/11285/head
Denys Rybalka 3 months ago
parent f23e982338
commit f4fb8fa4ef
No known key found for this signature in database
GPG Key ID: 1F6284E97DB46ED1

@ -375,7 +375,7 @@ impl MappableCommand {
file_picker, "Open file picker", file_picker, "Open file picker",
file_picker_in_current_buffer_directory, "Open file picker at current buffer's directory", file_picker_in_current_buffer_directory, "Open file picker at current buffer's directory",
file_picker_in_current_directory, "Open file picker at current working directory", file_picker_in_current_directory, "Open file picker at current working directory",
file_browser, "Open file browser at current working directory", file_browser, "Open file browser at current buffer's directory",
code_action, "Perform code action", code_action, "Perform code action",
buffer_picker, "Open buffer picker", buffer_picker, "Open buffer picker",
jumplist_picker, "Open jumplist picker", jumplist_picker, "Open jumplist picker",
@ -2950,13 +2950,19 @@ fn file_picker_in_current_directory(cx: &mut Context) {
} }
fn file_browser(cx: &mut Context) { fn file_browser(cx: &mut Context) {
let cwd = helix_stdx::env::current_working_dir(); let doc_dir = doc!(cx.editor)
if !cwd.exists() { .path()
cx.editor .and_then(|path| path.parent().map(|path| path.to_path_buf()));
.set_error("Current working directory does not exist");
return; let path = match doc_dir {
} Some(path) => path,
if let Ok(picker) = ui::file_browser(cwd) { None => {
cx.editor.set_error("Current buffer has no path or parent");
return;
}
};
if let Ok(picker) = ui::file_browser(path) {
cx.push_layer(Box::new(overlaid(picker))); cx.push_layer(Box::new(overlaid(picker)));
} }
} }

Loading…
Cancel
Save