Add file_browser for cwd and workspace root
This commit is contained in:
parent
68b252a5fd
commit
127a588e7f
1 changed files with 31 additions and 1 deletions
|
@ -375,7 +375,9 @@ 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 buffer's directory",
|
file_browser, "Open file browser in workspace root",
|
||||||
|
file_browser_in_current_buffer_directory, "Open file browser at current buffer's directory",
|
||||||
|
file_browser_in_current_directory, "Open file browser at current working 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,6 +2952,18 @@ fn file_picker_in_current_directory(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_browser(cx: &mut Context) {
|
fn file_browser(cx: &mut Context) {
|
||||||
|
let root = find_workspace().0;
|
||||||
|
if !root.exists() {
|
||||||
|
cx.editor.set_error("Workspace directory does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(picker) = ui::file_browser(root) {
|
||||||
|
cx.push_layer(Box::new(overlaid(picker)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn file_browser_in_current_buffer_directory(cx: &mut Context) {
|
||||||
let doc_dir = doc!(cx.editor)
|
let doc_dir = doc!(cx.editor)
|
||||||
.path()
|
.path()
|
||||||
.and_then(|path| path.parent().map(|path| path.to_path_buf()));
|
.and_then(|path| path.parent().map(|path| path.to_path_buf()));
|
||||||
|
@ -2964,6 +2978,9 @@ fn file_browser(cx: &mut Context) {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
cx.editor.set_error(
|
||||||
|
"Current buffer has no parent, opening file browser in current working directory",
|
||||||
|
);
|
||||||
cwd
|
cwd
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2973,6 +2990,19 @@ fn file_browser(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn file_browser_in_current_directory(cx: &mut Context) {
|
||||||
|
let cwd = helix_stdx::env::current_working_dir();
|
||||||
|
if !cwd.exists() {
|
||||||
|
cx.editor
|
||||||
|
.set_error("Current working directory does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(picker) = ui::file_browser(cwd) {
|
||||||
|
cx.push_layer(Box::new(overlaid(picker)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn buffer_picker(cx: &mut Context) {
|
fn buffer_picker(cx: &mut Context) {
|
||||||
let current = view!(cx.editor).doc;
|
let current = view!(cx.editor).doc;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue