diff options
| author | Fuwn <[email protected]> | 2025-02-24 06:04:35 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-24 06:04:35 -0800 |
| commit | bb3adb028da4bf0f11790c5f081d199cae659201 (patch) | |
| tree | 02a4376e860277b59280894430eccaacac0064cd /Sora/Views/SearchSuggestionsView.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-bb3adb028da4bf0f11790c5f081d199cae659201.tar.xz sora-testing-bb3adb028da4bf0f11790c5f081d199cae659201.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Views/SearchSuggestionsView.swift')
| -rw-r--r-- | Sora/Views/SearchSuggestionsView.swift | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Sora/Views/SearchSuggestionsView.swift b/Sora/Views/SearchSuggestionsView.swift index 34ccfbc..2a1a8d6 100644 --- a/Sora/Views/SearchSuggestionsView.swift +++ b/Sora/Views/SearchSuggestionsView.swift @@ -3,8 +3,13 @@ import SwiftUI struct SearchSuggestionsView: View { var tags: [BooruTag] @Binding var searchText: String - var lastSearchTag: String { - String(searchText.split(separator: " ").last ?? "") + private var lastSearchTag: String { + String(searchText.split(separator: " ").last ?? "").lowercased() + } + private var filteredTags: [BooruTag] { + guard !lastSearchTag.isEmpty else { return [] } + + return tags.filter { $0.name.lowercased().contains(lastSearchTag) } } var body: some View { @@ -14,7 +19,9 @@ struct SearchSuggestionsView: View { } ) { suggestion in Button { - searchText.replaceSubrange(searchText.range(of: lastSearchTag)!, with: suggestion.name) + if let range = searchText.range(of: lastSearchTag, options: .backwards) { + searchText.replaceSubrange(range, with: suggestion.name) + } } label: { Text(suggestion.name) } |