expose last matched pattern to allow correct index rendering

This commit is contained in:
Pascal Kuthe 2023-08-03 20:34:42 +02:00
parent af2c1e190c
commit 91a265eb6b
No known key found for this signature in database
GPG Key ID: D715E8655AE166A6
3 changed files with 36 additions and 3 deletions

View File

@ -64,7 +64,7 @@ impl Matcher {
const UNMATCHED: ScoreCell = ScoreCell {
score: 0,
// if matched is true then the consecutive bonus
// is always alteast BONUS_CONSECUTIVE so
// is always atleast BONUS_CONSECUTIVE so
// this constant can never occur naturally
consecutive_bonus: 0,
matched: true,

View File

@ -90,6 +90,7 @@ pub struct Nucleo<T: Sync + Send + 'static> {
item_count: u32,
pub matches: Vec<Match>,
pub pattern: MultiPattern,
pub last_matched_pattern: MultiPattern,
pub notify: Arc<(dyn Fn() + Sync + Send)>,
items: Arc<boxcar::Vec<T>>,
}
@ -110,6 +111,7 @@ impl<T: Sync + Send + 'static> Nucleo<T> {
pool,
matches: Vec::with_capacity(2 * 1024),
pattern: MultiPattern::new(&config, case_matching, columns as usize),
last_matched_pattern: MultiPattern::new(&config, case_matching, columns as usize),
worker: Arc::new(Mutex::new(worker)),
cleared: false,
item_count: 0,
@ -195,6 +197,7 @@ impl<T: Sync + Send + 'static> Nucleo<T> {
inner.running = false;
if !inner.was_canceled {
self.item_count = inner.item_count();
self.last_matched_pattern.clone_from(&inner.pattern);
self.matches.clone_from(&inner.matches);
}
}

View File

@ -165,11 +165,23 @@ pub enum Status {
Rescore,
}
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct MultiPattern {
pub cols: Vec<Pattern>,
}
impl Clone for MultiPattern {
fn clone(&self) -> Self {
Self {
cols: self.cols.clone(),
}
}
fn clone_from(&mut self, source: &Self) {
self.cols.clone_from(&source.cols)
}
}
impl MultiPattern {
pub fn new(
matcher_config: &MatcherConfig,
@ -205,7 +217,7 @@ impl MultiPattern {
}
}
#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct Pattern {
terms: Vec<PatternAtom>,
case_matching: CaseMatching,
@ -351,6 +363,24 @@ impl Pattern {
}
}
impl Clone for Pattern {
fn clone(&self) -> Self {
Self {
terms: self.terms.clone(),
case_matching: self.case_matching,
normalize: self.normalize,
status: self.status,
}
}
fn clone_from(&mut self, source: &Self) {
self.terms.clone_from(&source.terms);
self.case_matching = source.case_matching;
self.normalize = source.normalize;
self.status = source.status;
}
}
fn pattern_atoms(pattern: &str) -> impl Iterator<Item = &str> + '_ {
let mut saw_backslash = false;
pattern.split(move |c| {