Remember the last search choice between search current/all (issue #198)

This commit is contained in:
Yishi Lin 2018-08-24 02:02:57 +01:00
parent 5b9ffe9b7e
commit 29b8313be5
2 changed files with 18 additions and 1 deletions

View file

@ -577,13 +577,29 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
backAction(self)
}
}
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
// update the default search scope
SharedDefaults[.isSearchDefaultAll] = searchController.searchBar.scopeButtonTitles![selectedScope] == "All"
updateSearchResults(for: searchController)
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
// set the default search scope to "all"
if SharedDefaults[.isShowFolderOn] && SharedDefaults[.isSearchDefaultAll] {
searchController.searchBar.selectedScopeButtonIndex = searchController.searchBar.scopeButtonTitles?.index(of: "All") ?? 0
} else {
searchController.searchBar.selectedScopeButtonIndex = 0
}
return true
}
func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool {
// set the default search scope to "current"
searchController.searchBar.selectedScopeButtonIndex = 0
updateSearchResults(for: searchController)
return true
}
private func requestGitPassword(credential: GitCredential.Credential, lastPassword: String?) -> String? {

View file

@ -38,6 +38,7 @@ public extension DefaultsKeys {
static let isRememberPGPPassphraseOn = DefaultsKey<Bool>("isRememberPGPPassphraseOn")
static let isRememberGitCredentialPassphraseOn = DefaultsKey<Bool>("isRememberGitCredentialPassphraseOn")
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
static let isSearchDefaultAll = DefaultsKey<Bool>("isSearchDefaultAll")
static let passwordGeneratorFlavor = DefaultsKey<String>("passwordGeneratorFlavor")
static let encryptInArmored = DefaultsKey<Bool>("encryptInArmored")