Add command for picking files from CWD (#1600)

The `file_picker_at_current_directory` command opens the file picker at
the current working directory (CWD). This can be useful when paired with
the built-in `:cd` command which changes the CWD.

It has been mapped to `space F` by default.
This commit is contained in:
gavynriebau 2022-04-10 10:30:09 +08:00 committed by GitHub
parent 494306ad7a
commit 562874a720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -259,6 +259,7 @@ pub fn doc(&self) -> &str {
append_mode, "Insert after selection (append)", append_mode, "Insert after selection (append)",
command_mode, "Enter command mode", command_mode, "Enter command mode",
file_picker, "Open file picker", file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory",
code_action, "Perform code action", code_action, "Perform code action",
buffer_picker, "Open buffer picker", buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker", symbol_picker, "Open symbol picker",
@ -2047,6 +2048,12 @@ fn file_picker(cx: &mut Context) {
cx.push_layer(Box::new(overlayed(picker))); cx.push_layer(Box::new(overlayed(picker)));
} }
fn file_picker_in_current_directory(cx: &mut Context) {
let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("./"));
let picker = ui::file_picker(cwd, &cx.editor.config());
cx.push_layer(Box::new(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;

View File

@ -196,6 +196,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"space" => { "Space" "space" => { "Space"
"f" => file_picker, "f" => file_picker,
"F" => file_picker_in_current_directory,
"b" => buffer_picker, "b" => buffer_picker,
"s" => symbol_picker, "s" => symbol_picker,
"S" => workspace_symbol_picker, "S" => workspace_symbol_picker,