diff options
author | Gokul Soumya | 2022-07-19 15:58:14 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-12-15 08:52:44 +0000 |
commit | c64debc7412c0769db8186694bd89f85ea057b1b (patch) | |
tree | 9e0016e91c44bd14e32411ef162cd18c81f59c9c /helix-term/src | |
parent | db939801ebf299f11a6a52bdff7a3c9bfb87fc34 (diff) |
Add force_score() for scoring picker items without optimizations
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/ui/picker.rs | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 5e9ca3d8..8b5d20ec 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -469,34 +469,41 @@ impl<T: Item> Picker<T> { self.matches.sort_unstable(); } else { - let query = FuzzyQuery::new(pattern); - self.matches.clear(); - self.matches.extend( - self.options - .iter() - .enumerate() - .filter_map(|(index, option)| { - let text = option.filter_text(&self.editor_data); - - query - .fuzzy_match(&text, &self.matcher) - .map(|score| PickerMatch { - index, - score, - len: text.chars().count(), - }) - }), - ); - self.matches.sort_unstable(); + self.force_score(); } log::debug!("picker score {:?}", Instant::now().duration_since(now)); // reset cursor position self.cursor = 0; + let pattern = self.prompt.line(); self.previous_pattern.clone_from(pattern); } + pub fn force_score(&mut self) { + let pattern = self.prompt.line(); + + let query = FuzzyQuery::new(pattern); + self.matches.clear(); + self.matches.extend( + self.options + .iter() + .enumerate() + .filter_map(|(index, option)| { + let text = option.filter_text(&self.editor_data); + + query + .fuzzy_match(&text, &self.matcher) + .map(|score| PickerMatch { + index, + score, + len: text.chars().count(), + }) + }), + ); + self.matches.sort_unstable(); + } + /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`) pub fn move_by(&mut self, amount: usize, direction: Direction) { let len = self.matches.len(); |