Don't use word splitting during fuzzy matching (#8192)

main
Pascal Kuthe 8 months ago committed by GitHub
parent 0cfd46c14f
commit e6cdc5f9d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
use std::ops::DerefMut; use std::ops::DerefMut;
use nucleo::pattern::{AtomKind, CaseMatching, Pattern}; use nucleo::pattern::{Atom, AtomKind, CaseMatching};
use nucleo::Config; use nucleo::Config;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -32,12 +32,12 @@ pub fn fuzzy_match<T: AsRef<str>>(
pattern: &str, pattern: &str,
items: impl IntoIterator<Item = T>, items: impl IntoIterator<Item = T>,
path: bool, path: bool,
) -> Vec<(T, u32)> { ) -> Vec<(T, u16)> {
let mut matcher = MATCHER.lock(); let mut matcher = MATCHER.lock();
matcher.config = Config::DEFAULT; matcher.config = Config::DEFAULT;
if path { if path {
matcher.config.set_match_paths(); matcher.config.set_match_paths();
} }
let pattern = Pattern::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy); let pattern = Atom::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy, false);
pattern.match_list(items, &mut matcher) pattern.match_list(items, &mut matcher)
} }

@ -5,7 +5,7 @@ use crate::{
ctrl, key, shift, ctrl, key, shift,
}; };
use helix_core::fuzzy::MATCHER; use helix_core::fuzzy::MATCHER;
use nucleo::pattern::{AtomKind, CaseMatching, Pattern}; use nucleo::pattern::{Atom, AtomKind, CaseMatching};
use nucleo::{Config, Utf32Str}; use nucleo::{Config, Utf32Str};
use tui::{buffer::Buffer as Surface, widgets::Table}; use tui::{buffer::Buffer as Surface, widgets::Table};
@ -94,13 +94,13 @@ impl<T: Item> Menu<T> {
self.matches.clear(); self.matches.clear();
let mut matcher = MATCHER.lock(); let mut matcher = MATCHER.lock();
matcher.config = Config::DEFAULT; matcher.config = Config::DEFAULT;
let pattern = Pattern::new(pattern, CaseMatching::Ignore, AtomKind::Fuzzy); let pattern = Atom::new(pattern, CaseMatching::Ignore, AtomKind::Fuzzy, false);
let mut buf = Vec::new(); let mut buf = Vec::new();
let matches = self.options.iter().enumerate().filter_map(|(i, option)| { let matches = self.options.iter().enumerate().filter_map(|(i, option)| {
let text = option.filter_text(&self.editor_data); let text = option.filter_text(&self.editor_data);
pattern pattern
.score(Utf32Str::new(&text, &mut buf), &mut matcher) .score(Utf32Str::new(&text, &mut buf), &mut matcher)
.map(|score| (i as u32, score)) .map(|score| (i as u32, score as u32))
}); });
self.matches.extend(matches); self.matches.extend(matches);
self.matches self.matches

Loading…
Cancel
Save