changed search priority to prefer whole-word matches

This commit is contained in:
Mark 2023-09-25 17:54:32 +02:00
parent 36da1ab189
commit 0e38114c88

View File

@ -320,11 +320,16 @@ impl GuiElemTrait for LibraryBrowser {
r.find_iter(pat) r.find_iter(pat)
.map(|m| match pat[0..m.start()].chars().rev().next() { .map(|m| match pat[0..m.start()].chars().rev().next() {
// found at the start of h, reaches to the end (whole pattern is part of the match) // found at the start of h, reaches to the end (whole pattern is part of the match)
None if m.end() == pat.len() => 5.0, None if m.end() == pat.len() => 6.0,
// found at start of h // found at start of h
None => 4.0, None => 4.0,
Some(ch) if ch.is_whitespace() => match pat[m.end()..].chars().next() {
// whole word matches
None => 5.0,
Some(ch) if ch.is_whitespace() => 5.0,
// found after whitespace in h // found after whitespace in h
Some(ch) if ch.is_whitespace() => 3.0, Some(_) = 3.0,
},
// found somewhere else in h // found somewhere else in h
_ => 2.0, _ => 2.0,
}) })