mirror of
https://github.com/solaeus/nucleo.git
synced 2024-11-12 18:17:11 +00:00
expose last matched pattern to allow correct index rendering
This commit is contained in:
parent
af2c1e190c
commit
91a265eb6b
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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| {
|
||||
|
Loading…
Reference in New Issue
Block a user