Clear the timeline when the user begins searching

This commit is contained in:
Maurice Parker 2019-09-01 14:49:56 -05:00
parent a5298f0381
commit dfc3046bf0
2 changed files with 22 additions and 18 deletions

View File

@ -427,11 +427,13 @@ extension MasterTimelineViewController: UISearchBarDelegate {
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
coordinator.beginSearching()
searchBar.showsScopeBar = true
return true
}
func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool {
coordinator.endSearching()
searchBar.showsScopeBar = false
return true
}

View File

@ -530,25 +530,27 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func searchArticles(_ searchString: String, _ searchScope: SearchScope) {
guard !searchString.isEmpty else {
isSearching = false
lastSearchString = ""
lastSearchScope = nil
searchArticleIds = nil
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
timelineFetcher = fetcher
}
return
}
if !isSearching {
isSearching = true
searchArticleIds = Set(articles.map { $0.articleID })
}
func beginSearching() {
isSearching = true
searchArticleIds = Set(articles.map { $0.articleID })
timelineFetcher = nil
}
func endSearching() {
isSearching = false
lastSearchString = ""
lastSearchScope = nil
searchArticleIds = nil
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
timelineFetcher = fetcher
}
}
func searchArticles(_ searchString: String, _ searchScope: SearchScope) {
guard isSearching else { return }
if searchString.count < 3 {
timelineFetcher = nil
return