on master help sign in
buffer picker: Mark current view with (*)
commit47e282804d4206050a24ce3d1bfa18086b755265 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 21 Dec 2020, 17:58 (6 years ago) parent3d3295b
2 files changed+15−7
helix-term/src/ui/mod.rs+10−4 helix-term/src/ui/picker.rs+5−3
helix-term/src/ui/mod.rs+10−4
@@ -38,7 +38,7 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
3838 files.take(MAX).collect(),
3939 |path: &PathBuf| {
4040 // format_fn
41− path.strip_prefix("./").unwrap().to_str().unwrap()
41+ path.strip_prefix("./").unwrap().to_str().unwrap().into()
4242 },
4343 |editor: &mut Editor, path: &PathBuf| {
4444 let size = editor.view().unwrap().size;
@@ -56,11 +56,17 @@ pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>,
5656 .enumerate()
5757 .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
5858 .collect(),
59− |(path, index): &(Option<PathBuf>, usize)| {
59+ move |(path, index): &(Option<PathBuf>, usize)| {
6060 // format_fn
6161 match path {
62− Some(path) => path.to_str().unwrap(),
63− None => "[NEW]",
62+ Some(path) => {
63+ if *index == current {
64+ format!("{} (*)", path.to_str().unwrap()).into()
65+ } else {
66+ path.to_str().unwrap().into()
67+ }
68+ }
69+ None => "[NEW]".into(),
6470 }
6571 },
6672 |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
helix-term/src/ui/picker.rs+5−3
@@ -10,6 +10,8 @@ use tui::{
1010use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
1111use fuzzy_matcher::FuzzyMatcher;
1212
13+use std::borrow::Cow;
14+
1315use crate::ui::{Prompt, PromptEvent};
1416use helix_core::Position;
1517use helix_view::Editor;
@@ -25,14 +27,14 @@ pub struct Picker<T> {
2527 // pattern: String,
2628 prompt: Prompt,
2729
28− format_fn: Box<dyn Fn(&T) -> &str>,
30+ format_fn: Box<dyn Fn(&T) -> Cow<str>>,
2931 callback_fn: Box<dyn Fn(&mut Editor, &T)>,
3032}
3133
3234impl<T> Picker<T> {
3335 pub fn new(
3436 options: Vec<T>,
35− format_fn: impl Fn(&T) -> &str + 'static,
37+ format_fn: impl Fn(&T) -> Cow<str> + 'static,
3638 callback_fn: impl Fn(&mut Editor, &T) + 'static,
3739 ) -> Self {
3840 let prompt = Prompt::new(
@@ -82,7 +84,7 @@ impl<T> Picker<T> {
8284 let text = (format_fn)(option);
8385 // TODO: using fuzzy_indices could give us the char idx for match highlighting
8486 matcher
85− .fuzzy_match(text, pattern)
87+ .fuzzy_match(&text, pattern)
8688 .map(|score| (index, score))
8789 }),
8890 );