aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-10-22 03:07:41 +0000
committerBlaž Hrastnik2021-10-22 03:15:18 +0000
commit182a59b5528075c0171756bff71275db8a7995f0 (patch)
tree1f477382ef5ec5e6764d98d680f0fd9fc0e06fb6 /helix-term/src/ui
parent3b032e8e1fd342261b153aeb375f9c0e8d882b34 (diff)
Update to rust 1.56 + 2021 edition
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/menu.rs32
-rw-r--r--helix-term/src/ui/picker.rs23
2 files changed, 22 insertions, 33 deletions
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index 055593fd..1130089d 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -64,25 +64,23 @@ impl<T: Item> Menu<T> {
}
pub fn score(&mut self, pattern: &str) {
- // need to borrow via pattern match otherwise it complains about simultaneous borrow
- let Self {
- ref mut matcher,
- ref mut matches,
- ref options,
- ..
- } = *self;
-
// reuse the matches allocation
- matches.clear();
- matches.extend(options.iter().enumerate().filter_map(|(index, option)| {
- let text = option.filter_text();
- // TODO: using fuzzy_indices could give us the char idx for match highlighting
- matcher
- .fuzzy_match(text, pattern)
- .map(|score| (index, score))
- }));
+ self.matches.clear();
+ self.matches.extend(
+ self.options
+ .iter()
+ .enumerate()
+ .filter_map(|(index, option)| {
+ let text = option.filter_text();
+ // TODO: using fuzzy_indices could give us the char idx for match highlighting
+ self.matcher
+ .fuzzy_match(text, pattern)
+ .map(|score| (index, score))
+ }),
+ );
// matches.sort_unstable_by_key(|(_, score)| -score);
- matches.sort_unstable_by_key(|(index, _score)| options[*index].sort_text());
+ self.matches
+ .sort_unstable_by_key(|(index, _score)| self.options[*index].sort_text());
// reset cursor position
self.cursor = None;
diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs
index 6f584178..1f08cf13 100644
--- a/helix-term/src/ui/picker.rs
+++ b/helix-term/src/ui/picker.rs
@@ -233,37 +233,28 @@ impl<T> Picker<T> {
}
pub fn score(&mut self) {
- // need to borrow via pattern match otherwise it complains about simultaneous borrow
- let Self {
- ref mut matcher,
- ref mut matches,
- ref filters,
- ref format_fn,
- ..
- } = *self;
-
let pattern = &self.prompt.line;
// reuse the matches allocation
- matches.clear();
- matches.extend(
+ self.matches.clear();
+ self.matches.extend(
self.options
.iter()
.enumerate()
.filter_map(|(index, option)| {
// filter options first before matching
- if !filters.is_empty() {
- filters.binary_search(&index).ok()?;
+ if !self.filters.is_empty() {
+ self.filters.binary_search(&index).ok()?;
}
// TODO: maybe using format_fn isn't the best idea here
- let text = (format_fn)(option);
+ let text = (self.format_fn)(option);
// TODO: using fuzzy_indices could give us the char idx for match highlighting
- matcher
+ self.matcher
.fuzzy_match(&text, pattern)
.map(|score| (index, score))
}),
);
- matches.sort_unstable_by_key(|(_, score)| -score);
+ self.matches.sort_unstable_by_key(|(_, score)| -score);
// reset cursor position
self.cursor = 0;