From 29b8313be5af7a6150480b1e8fd4a9c78a2c418d Mon Sep 17 00:00:00 2001 From: Yishi Lin Date: Fri, 24 Aug 2018 02:02:57 +0100 Subject: [PATCH] Remember the last search choice between search current/all (issue #198) --- pass/Controllers/PasswordsViewController.swift | 18 +++++++++++++++++- passKit/Helpers/DefaultsKeys.swift | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) 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")