mirror of https://github.com/helix-editor/helix
buffer picker: Mark current view with (*)
parent
3d3295bb75
commit
47e282804d
|
@ -38,7 +38,7 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
|
||||||
files.take(MAX).collect(),
|
files.take(MAX).collect(),
|
||||||
|path: &PathBuf| {
|
|path: &PathBuf| {
|
||||||
// format_fn
|
// format_fn
|
||||||
path.strip_prefix("./").unwrap().to_str().unwrap()
|
path.strip_prefix("./").unwrap().to_str().unwrap().into()
|
||||||
},
|
},
|
||||||
|editor: &mut Editor, path: &PathBuf| {
|
|editor: &mut Editor, path: &PathBuf| {
|
||||||
let size = editor.view().unwrap().size;
|
let size = editor.view().unwrap().size;
|
||||||
|
@ -56,11 +56,17 @@ pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>,
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
|
.map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
|
||||||
.collect(),
|
.collect(),
|
||||||
|(path, index): &(Option<PathBuf>, usize)| {
|
move |(path, index): &(Option<PathBuf>, usize)| {
|
||||||
// format_fn
|
// format_fn
|
||||||
match path {
|
match path {
|
||||||
Some(path) => path.to_str().unwrap(),
|
Some(path) => {
|
||||||
None => "[NEW]",
|
if *index == current {
|
||||||
|
format!("{} (*)", path.to_str().unwrap()).into()
|
||||||
|
} else {
|
||||||
|
path.to_str().unwrap().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => "[NEW]".into(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
|
|editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
|
||||||
|
|
|
@ -10,6 +10,8 @@ use tui::{
|
||||||
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
|
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
|
||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::ui::{Prompt, PromptEvent};
|
use crate::ui::{Prompt, PromptEvent};
|
||||||
use helix_core::Position;
|
use helix_core::Position;
|
||||||
use helix_view::Editor;
|
use helix_view::Editor;
|
||||||
|
@ -25,14 +27,14 @@ pub struct Picker<T> {
|
||||||
// pattern: String,
|
// pattern: String,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
|
|
||||||
format_fn: Box<dyn Fn(&T) -> &str>,
|
format_fn: Box<dyn Fn(&T) -> Cow<str>>,
|
||||||
callback_fn: Box<dyn Fn(&mut Editor, &T)>,
|
callback_fn: Box<dyn Fn(&mut Editor, &T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Picker<T> {
|
impl<T> Picker<T> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
options: Vec<T>,
|
options: Vec<T>,
|
||||||
format_fn: impl Fn(&T) -> &str + 'static,
|
format_fn: impl Fn(&T) -> Cow<str> + 'static,
|
||||||
callback_fn: impl Fn(&mut Editor, &T) + 'static,
|
callback_fn: impl Fn(&mut Editor, &T) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let prompt = Prompt::new(
|
let prompt = Prompt::new(
|
||||||
|
@ -82,7 +84,7 @@ impl<T> Picker<T> {
|
||||||
let text = (format_fn)(option);
|
let text = (format_fn)(option);
|
||||||
// TODO: using fuzzy_indices could give us the char idx for match highlighting
|
// TODO: using fuzzy_indices could give us the char idx for match highlighting
|
||||||
matcher
|
matcher
|
||||||
.fuzzy_match(text, pattern)
|
.fuzzy_match(&text, pattern)
|
||||||
.map(|score| (index, score))
|
.map(|score| (index, score))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue