summaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-21 07:23:05 +0000
committerBlaž Hrastnik2020-12-21 07:26:22 +0000
commit3d3295bb759994d4fbf328c126678f63e0c38d4f (patch)
treeca93396f3fa0c42a8c6f0c2277f41b1d344fe791 /helix-term/src/ui/mod.rs
parentea502c8665332932b2311df3852b5ac8df6509af (diff)
ui: buffer picker on ctrl-b
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs28
1 files changed, 26 insertions, 2 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;
+ }
+ },
+ )
+}