diff --git a/pass/Controllers/PasswordsViewController.swift b/pass/Controllers/PasswordsViewController.swift index 2129d8c..f6d570d 100644 --- a/pass/Controllers/PasswordsViewController.swift +++ b/pass/Controllers/PasswordsViewController.swift @@ -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? { diff --git a/passKit/Helpers/DefaultsKeys.swift b/passKit/Helpers/DefaultsKeys.swift index 508f395..d1e972e 100644 --- a/passKit/Helpers/DefaultsKeys.swift +++ b/passKit/Helpers/DefaultsKeys.swift @@ -38,6 +38,7 @@ public extension DefaultsKeys { static let isRememberPGPPassphraseOn = DefaultsKey("isRememberPGPPassphraseOn") static let isRememberGitCredentialPassphraseOn = DefaultsKey("isRememberGitCredentialPassphraseOn") static let isShowFolderOn = DefaultsKey("isShowFolderOn") + static let isSearchDefaultAll = DefaultsKey("isSearchDefaultAll") static let passwordGeneratorFlavor = DefaultsKey("passwordGeneratorFlavor") static let encryptInArmored = DefaultsKey("encryptInArmored")