Hide keyboard on tap, more robust search algorithm, option to search by dictionary word or definition

This commit is contained in:
Madeline
2022-10-28 00:52:53 -04:00
parent c74a2f520c
commit 0fea23b057
5 changed files with 86 additions and 11 deletions

View File

@@ -52,11 +52,21 @@ class TokiDictionaryViewModel: ObservableObject {
entryMatch = true
}
// Check if any part of the word definitions match in English, even partially
// Check if any part of the word definitions match in English, even partially, but
// only by prefix (if one of the definition words matches the beginning of the word with
// the search term)
for definition in value.definitions {
if definition.definition.contains(input) {
entryMatch = true
let capturePattern = #"(\w+)"#
let captures = self.searchStringForRegex(string: definition.definition, regex: capturePattern)
for capture in captures {
if capture.hasPrefix(input) {
entryMatch = true
}
}
// Commented out, less strict matching that will match on any substring match
// if definition.definition.contains(input) {
// entryMatch = true
// }
}
// Add to dictionary