diff options
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/mod.rs | 28 | ||||
-rw-r--r-- | helix-term/src/ui/picker.rs | 10 | ||||
-rw-r--r-- | helix-term/src/ui/prompt.rs | 10 |
3 files changed, 38 insertions, 10 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index b778f531..f9480dd4 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -15,7 +15,7 @@ pub fn text_color() -> Style { Style::default().fg(Color::Rgb(219, 191, 239)) // lilac } -use std::path::PathBuf; +use std::path::{Path, PathBuf}; pub fn file_picker(root: &str) -> Picker<PathBuf> { use ignore::Walk; // TODO: determine root based on git root @@ -38,7 +38,7 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> { files.take(MAX).collect(), |path: &PathBuf| { // format_fn - path.strip_prefix("./").unwrap().to_str().unwrap() // TODO: render paths without ./ + path.strip_prefix("./").unwrap().to_str().unwrap() }, |editor: &mut Editor, path: &PathBuf| { let size = editor.view().unwrap().size; @@ -46,3 +46,27 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> { }, ) } + +use helix_view::View; +pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>, usize)> { + use helix_view::Editor; + Picker::new( + views + .iter() + .enumerate() + .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i)) + .collect(), + |(path, index): &(Option<PathBuf>, usize)| { + // format_fn + match path { + Some(path) => path.to_str().unwrap(), + None => "[NEW]", + } + }, + |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| { + if index < editor.views.len() { + editor.focus = index; + } + }, + ) +} diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 0a12cff9..94eec2eb 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -123,10 +123,12 @@ impl<T> Component for Picker<T> { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { - // remove the layer - compositor.pop(); - }))); + let close_fn = EventResult::Consumed(Some(Box::new( + |compositor: &mut Compositor, editor: &mut Editor| { + // remove the layer + compositor.pop(); + }, + ))); match key_event { // KeyEvent { diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 58efd560..7abc08c2 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -167,10 +167,12 @@ impl Component for Prompt { _ => return EventResult::Ignored, }; - let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| { - // remove the layer - compositor.pop(); - }))); + let close_fn = EventResult::Consumed(Some(Box::new( + |compositor: &mut Compositor, editor: &mut Editor| { + // remove the layer + compositor.pop(); + }, + ))); match event { KeyEvent { |