Skip to content

Commit

Permalink
Find file (space .)
Browse files Browse the repository at this point in the history
Based on doom emacs find-file but also wanted to show an alternative to
file explorer #2377.
  • Loading branch information
pickfire committed Sep 29, 2022
1 parent bdc7b35 commit c925fbd
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 52 deletions.
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ This layer is a kludge of mappings, mostly pickers.
| ----- | ----------- | ------- |
| `f` | Open file picker | `file_picker` |
| `F` | Open file picker at current working directory | `file_picker_in_current_directory` |
| `.` | Open find file picker | `find_file_picker` |
| `b` | Open buffer picker | `buffer_picker` |
| `j` | Open jumplist picker | `jumplist_picker` |
| `k` | Show documentation for item under cursor in a [popup](#popup) (**LSP**) | `hover` |
Expand Down
2 changes: 2 additions & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ serde = { version = "1.0", features = ["derive"] }
# ripgrep for global search
grep-regex = "0.1.10"
grep-searcher = "0.1.10"
libc = "0.2.133"
number_prefix = "0.4.0"

[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
Expand Down
11 changes: 11 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ impl MappableCommand {
command_mode, "Enter command mode",
file_picker, "Open file picker",
file_picker_in_current_directory, "Open file picker at current working directory",
find_file_picker, "Open find file picker",
code_action, "Perform code action",
buffer_picker, "Open buffer picker",
jumplist_picker, "Open jumplist picker",
Expand Down Expand Up @@ -2238,6 +2239,16 @@ fn file_picker_in_current_directory(cx: &mut Context) {
cx.push_layer(Box::new(overlayed(picker)));
}

fn find_file_picker(cx: &mut Context) {
let doc = doc!(cx.editor);
let doc_parent = doc.path().and_then(|p| p.parent()).map(|p| p.to_owned());
let cwd = doc_parent
.or_else(|| std::env::current_dir().ok())
.unwrap_or_else(|| PathBuf::from("./"));
let picker = ui::find_file_picker(cwd);
cx.push_layer(Box::new(overlayed(picker)));
}

fn buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;

Expand Down
1 change: 1 addition & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"space" => { "Space"
"f" => file_picker,
"F" => file_picker_in_current_directory,
"." => find_file_picker,
"b" => buffer_picker,
"j" => jumplist_picker,
"s" => symbol_picker,
Expand Down
7 changes: 6 additions & 1 deletion helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use completion::Completion;
pub use editor::EditorView;
pub use markdown::Markdown;
pub use menu::Menu;
pub use picker::{FileLocation, FilePicker, Picker};
pub use picker::{FileLocation, FilePicker, FindFilePicker, Picker};
pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
Expand Down Expand Up @@ -200,6 +200,11 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
)
}

/// Based on find-file on doom emacs (SPC . or SPC f f).
pub fn find_file_picker(dir: PathBuf) -> FindFilePicker {
FindFilePicker::new(dir)
}

pub mod completers {
use crate::ui::prompt::Completion;
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
Expand Down
Loading

0 comments on commit c925fbd

Please sign in to comment.