summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
authorGokul Soumya2021-08-12 07:00:42 +0000
committerGitHub2021-08-12 07:00:42 +0000
commitd84f8b5fdef71da87ee108db07ba1167fc6a769b (patch)
tree057f87cb1107aae3eb966ff3e228b15d3e36ff2e /helix-term/src/ui/mod.rs
parent7d51805e94a461834ce34e0829da5859d1f9db32 (diff)
Show file preview in split pane in fuzzy finder (#534)
* Add preview pane for fuzzy finder * Fix picker preview lag by caching * Add picker preview for document symbols * Cache picker preview per document instead of view * Use line instead of range for preview doc * Add picker preview for buffer picker * Fix render bug and refactor picker * Refactor picker preview rendering * Split picker and preview and compose The current selected item is cloned on every event, which is undesirable * Refactor out clones in previewed picker * Retrieve doc from editor if possible in filepicker * Disable syntax highlight for picker preview Files already loaded in memory have syntax highlighting enabled * Ignore directory symlinks in file picker * Cleanup unnecessary pubs and derives * Remove unnecessary highlight from file picker * Reorganize buffer rendering * Use normal picker for code actions * Remove unnecessary generics and trait impls * Remove prepare_for_render and make render mutable * Skip picker preview if screen small, less padding
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs42
1 files changed, 20 insertions, 22 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index f68ad0a7..d1af0e48 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -13,7 +13,7 @@ pub use completion::Completion;
pub use editor::EditorView;
pub use markdown::Markdown;
pub use menu::Menu;
-pub use picker::Picker;
+pub use picker::{FilePicker, Picker};
pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
@@ -73,29 +73,26 @@ pub fn regex_prompt(
)
}
-pub fn file_picker(root: PathBuf) -> Picker<PathBuf> {
+pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> {
use ignore::Walk;
use std::time;
- let files = Walk::new(root.clone()).filter_map(|entry| match entry {
- Ok(entry) => {
- // filter dirs, but we might need special handling for symlinks!
- if !entry.file_type().map_or(false, |entry| entry.is_dir()) {
- let time = if let Ok(metadata) = entry.metadata() {
- metadata
- .accessed()
- .or_else(|_| metadata.modified())
- .or_else(|_| metadata.created())
- .unwrap_or(time::UNIX_EPOCH)
- } else {
- time::UNIX_EPOCH
- };
-
- Some((entry.into_path(), time))
- } else {
- None
- }
+ let files = Walk::new(root.clone()).filter_map(|entry| {
+ let entry = entry.ok()?;
+ // Path::is_dir() traverses symlinks, so we use it over DirEntry::is_dir
+ if entry.path().is_dir() {
+ // Will give a false positive if metadata cannot be read (eg. permission error)
+ return None;
}
- Err(_err) => None,
+
+ let time = entry.metadata().map_or(time::UNIX_EPOCH, |metadata| {
+ metadata
+ .accessed()
+ .or_else(|_| metadata.modified())
+ .or_else(|_| metadata.created())
+ .unwrap_or(time::UNIX_EPOCH)
+ });
+
+ Some((entry.into_path(), time))
});
let mut files: Vec<_> = if root.join(".git").is_dir() {
@@ -109,7 +106,7 @@ pub fn file_picker(root: PathBuf) -> Picker<PathBuf> {
let files = files.into_iter().map(|(path, _)| path).collect();
- Picker::new(
+ FilePicker::new(
files,
move |path: &PathBuf| {
// format_fn
@@ -124,6 +121,7 @@ pub fn file_picker(root: PathBuf) -> Picker<PathBuf> {
.open(path.into(), action)
.expect("editor.open failed");
},
+ |_editor, path| Some((path.clone(), None)),
)
}