on master help sign in
buffer picker: Mark current view with (*)
47e2828Blaž Hrastnik
helix-term/src/ui/mod.rs+10−4
@@ -38,7 +38,7 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
38 files.take(MAX).collect(),
38 files.take(MAX).collect(),
39 |path: &PathBuf| {
39 |path: &PathBuf| {
40 // format_fn
40 // format_fn
41− path.strip_prefix("./").unwrap().to_str().unwrap()
41+ path.strip_prefix("./").unwrap().to_str().unwrap().into()
42 },
42 },
43 |editor: &mut Editor, path: &PathBuf| {
43 |editor: &mut Editor, path: &PathBuf| {
44 let size = editor.view().unwrap().size;
44 let size = editor.view().unwrap().size;
@@ -56,11 +56,17 @@ pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>,
56 .enumerate()
56 .enumerate()
57 .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
57 .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
58 .collect(),
58 .collect(),
59− |(path, index): &(Option<PathBuf>, usize)| {
59+ move |(path, index): &(Option<PathBuf>, usize)| {
60 // format_fn
60 // format_fn
61 match path {
61 match path {
62+ Some(path) => {
63+ if *index == current {
64+ format!("{} (*)", path.to_str().unwrap()).into()
65+ } else {
62− Some(path) => path.to_str().unwrap(),
66+ path.to_str().unwrap().into()
67+ }
68+ }
63− None => "[NEW]",
69+ None => "[NEW]".into(),
64 }
70 }
65 },
71 },
66 |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
72 |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
helix-term/src/ui/picker.rs+5−3
@@ -10,6 +10,8 @@ use tui::{
10use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
10use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
11use fuzzy_matcher::FuzzyMatcher;
11use fuzzy_matcher::FuzzyMatcher;
12
12
13+use std::borrow::Cow;
14+
13use crate::ui::{Prompt, PromptEvent};
15use crate::ui::{Prompt, PromptEvent};
14use helix_core::Position;
16use helix_core::Position;
15use helix_view::Editor;
17use helix_view::Editor;
@@ -25,14 +27,14 @@ pub struct Picker<T> {
25 // pattern: String,
27 // pattern: String,
26 prompt: Prompt,
28 prompt: Prompt,
27
29
28− format_fn: Box<dyn Fn(&T) -> &str>,
30+ format_fn: Box<dyn Fn(&T) -> Cow<str>>,
29 callback_fn: Box<dyn Fn(&mut Editor, &T)>,
31 callback_fn: Box<dyn Fn(&mut Editor, &T)>,
30}
32}
31
33
32impl<T> Picker<T> {
34impl<T> Picker<T> {
33 pub fn new(
35 pub fn new(
34 options: Vec<T>,
36 options: Vec<T>,
35− format_fn: impl Fn(&T) -> &str + 'static,
37+ format_fn: impl Fn(&T) -> Cow<str> + 'static,
36 callback_fn: impl Fn(&mut Editor, &T) + 'static,
38 callback_fn: impl Fn(&mut Editor, &T) + 'static,
37 ) -> Self {
39 ) -> Self {
38 let prompt = Prompt::new(
40 let prompt = Prompt::new(
@@ -82,7 +84,7 @@ impl<T> Picker<T> {
82 let text = (format_fn)(option);
84 let text = (format_fn)(option);
83 // TODO: using fuzzy_indices could give us the char idx for match highlighting
85 // TODO: using fuzzy_indices could give us the char idx for match highlighting
84 matcher
86 matcher
85− .fuzzy_match(text, pattern)
87+ .fuzzy_match(&text, pattern)
86 .map(|score| (index, score))
88 .map(|score| (index, score))
87 }),
89 }),
88 );
90 );