Skip to content

Commit

Permalink
Build regex on invalidate to unify code paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottslaughter committed Oct 20, 2023
1 parent ffda863 commit 1ad7275
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,10 +1143,6 @@ impl SearchState {
if self.query != self.last_query {
invalidate = true;
self.last_query = self.query.clone();
if self.whole_word {
let regex_string = format!("\\b{}\\b", escape(&self.query));
self.last_word_regex = Some(Regex::new(regex_string.as_str()).unwrap());
}
}

// Invalidate when the search field changes.
Expand All @@ -1159,10 +1155,6 @@ impl SearchState {
if self.whole_word != self.last_whole_word {
invalidate = true;
self.last_whole_word = self.whole_word;
if self.whole_word {
let regex_string = format!("\\b{}\\b", escape(&self.query));
self.last_word_regex = Some(Regex::new(regex_string.as_str()).unwrap());
}
}

// Invalidate when EXCLUDING collapsed entries. (I.e., because the
Expand All @@ -1181,6 +1173,11 @@ impl SearchState {
}

if invalidate {
if self.whole_word {
let regex_string = format!("\\b{}\\b", escape(&self.query));
self.last_word_regex = Some(Regex::new(&regex_string).unwrap());
}

self.clear();
}
}
Expand Down

0 comments on commit 1ad7275

Please sign in to comment.