@State var selectedEvolution: StageType = .behavior
@State var isSearching: Bool = false
+ private let changeDebouncer: Debouncer = Debouncer(seconds: 0.05)
+
@AppStorage("viewStyle") var viewStyle: ViewStyle = .horizontal
let zoomRange = Constants.kMinZoom...Constants.kMaxZoom
@State var searchTerm = ""
@State var selectedTerm = 0
- var results: [Range<String.Index>] {
+ @State var results: [Range<String.Index>] = []
+
+ private func updateRanges() {
if !isSearching || searchTerm.isEmpty {
- return []
+ results = []
}
let options: NSString.CompareOptions = [.caseInsensitive, .diacriticInsensitive]
var searchRange = document.text.startIndex..<document.text.endIndex
searchRange = range.upperBound..<document.text.endIndex
}
- return ranges
+ results = ranges
}
},
onDismiss: {
- withAnimation {
- isSearching = false
- }
+ isSearching = false
}
)
.onChange(
of: searchTerm,
{
- selectedTerm = 0
+ changeDebouncer.debounce {
+ updateRanges()
+ selectedTerm = 0
+ }
})
Divider()
}