match highlight behavior with search behavior
This commit is contained in:
parent
8caff1a535
commit
05d8846f6c
|
@ -82,11 +82,12 @@ extension ConversationSearchController: UISearchResultsUpdating {
|
|||
public func updateSearchResults(for searchController: UISearchController) {
|
||||
Logger.verbose("searchBar.text: \( searchController.searchBar.text ?? "<blank>")")
|
||||
|
||||
guard let searchText = searchController.searchBar.text?.stripped else {
|
||||
guard let rawSearchText = searchController.searchBar.text?.stripped else {
|
||||
self.resultsBar.updateResults(resultSet: nil)
|
||||
self.delegate?.conversationSearchController(self, didUpdateSearchResults: nil)
|
||||
return
|
||||
}
|
||||
let searchText = FullTextSearchFinder.normalize(text: rawSearchText)
|
||||
BenchManager.startEvent(title: "Conversation Search", eventId: searchText)
|
||||
|
||||
guard searchText.count >= ConversationSearchController.kMinimumSearchTextLength else {
|
||||
|
|
|
@ -708,10 +708,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
initWithString:text
|
||||
attributes:@{ NSFontAttributeName : font, NSForegroundColorAttributeName : textColor }];
|
||||
if (searchText.length >= ConversationSearchController.kMinimumSearchTextLength) {
|
||||
NSString *searchableText = [FullTextSearchFinder normalizeWithText:searchText];
|
||||
NSError *error;
|
||||
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:searchText
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:&error];
|
||||
NSRegularExpression *regex =
|
||||
[[NSRegularExpression alloc] initWithPattern:[NSRegularExpression escapedPatternForString:searchableText]
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:&error];
|
||||
OWSAssertDebug(error == nil);
|
||||
for (NSTextCheckingResult *match in
|
||||
[regex matchesInString:text options:NSMatchingWithoutAnchoringBounds range:NSMakeRange(0, text.length)]) {
|
||||
|
|
|
@ -138,6 +138,7 @@ public class FullTextSearchFinder: NSObject {
|
|||
// This is a hot method, especially while running large migrations.
|
||||
// Changes to it should go through a profiler to make sure large migrations
|
||||
// aren't adversely affected.
|
||||
@objc
|
||||
public class func normalize(text: String) -> String {
|
||||
// 1. Filter out invalid characters.
|
||||
let filtered = text.removeCharacters(characterSet: charactersToRemove)
|
||||
|
|
Loading…
Reference in New Issue