@@ -23,6 +23,8 @@ pub struct Picker<T> {
2323 matcher: Box<Matcher>,
2424 /// (index, score)
2525 matches: Vec<(usize, i64)>,
26+ /// Filter over original options.
27+ filters: Vec<usize>, // could be optimized into bit but not worth it now
2628
2729 cursor: usize,
2830 // pattern: String,
@@ -50,6 +52,7 @@ impl<T> Picker<T> {
5052 options,
5153 matcher: Box::new(Matcher::default()),
5254 matches: Vec::new(),
55+ filters: Vec::new(),
5356 cursor: 0,
5457 prompt,
5558 format_fn: Box::new(format_fn),
@@ -68,6 +71,7 @@ impl<T> Picker<T> {
6871 ref mut options,
6972 ref mut matcher,
7073 ref mut matches,
74+ ref filters,
7175 ref format_fn,
7276 ..
7377 } = *self;
@@ -81,6 +85,10 @@ impl<T> Picker<T> {
8185 .iter()
8286 .enumerate()
8387 .filter_map(|(index, option)| {
88+ // filter options first before matching
89+ if !filters.is_empty() {
90+ filters.binary_search(&index).ok()?;
91+ }
8492 // TODO: maybe using format_fn isn't the best idea here
8593 let text = (format_fn)(option);
8694 // TODO: using fuzzy_indices could give us the char idx for match highlighting
@@ -114,6 +122,14 @@ impl<T> Picker<T> {
114122 .get(self.cursor)
115123 .map(|(index, _score)| &self.options[*index])
116124 }
125+
126+ pub fn save_filter(&mut self) {
127+ self.filters.clear();
128+ self.filters
129+ .extend(self.matches.iter().map(|(index, _)| *index));
130+ self.filters.sort_unstable(); // used for binary search later
131+ self.prompt.clear();
132+ }
117133}
118134
119135// process:
@@ -205,6 +221,12 @@ impl<T: 'static> Component for Picker<T> {
205221 }
206222 return close_fn;
207223 }
224+ KeyEvent {
225+ code: KeyCode::Char(' '),
226+ modifiers: KeyModifiers::CONTROL,
227+ } => {
228+ self.save_filter();
229+ }
208230 _ => {
209231 if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
210232 // TODO: recalculate only if pattern changed