From 9ec7073e84f8b83f076e242cdd60c7b5260f0b18 Mon Sep 17 00:00:00 2001 From: Mingshen Sun Date: Fri, 10 Mar 2023 22:01:18 -0800 Subject: [PATCH] Recover search status back from the password detail --- .../PasswordNavigationViewController.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pass/Controllers/PasswordNavigationViewController.swift b/pass/Controllers/PasswordNavigationViewController.swift index af81bfa..fb9aa09 100644 --- a/pass/Controllers/PasswordNavigationViewController.swift +++ b/pass/Controllers/PasswordNavigationViewController.swift @@ -32,6 +32,7 @@ class PasswordNavigationViewController: UIViewController { var viewingUnsyncedPasswords = false var tapTabBarTime: TimeInterval = 0 + var searchText: String? lazy var passwordManager = PasswordManager(viewController: self) @@ -109,6 +110,16 @@ class PasswordNavigationViewController: UIViewController { configureNavigationBar() } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + if searchText != nil { + DispatchQueue.main.async { + self.searchBar.text = self.searchText + self.searchController.isActive = true + } + } + } + private func configureSearchBar() { if Defaults.isShowFolderOn { searchBar.scopeButtonTitles = SearchBarScope.allCases.map(\.localizedName) @@ -388,6 +399,7 @@ extension PasswordNavigationViewController { extension PasswordNavigationViewController: UISearchBarDelegate { func search(matching text: String) { + searchText = text dataSource?.showTableEntries(matching: text) tableView.reloadData() } @@ -414,6 +426,7 @@ extension PasswordNavigationViewController: UISearchBarDelegate { searchBar.selectedScopeButtonIndex = SearchBarScope.current.rawValue } activateSearch(searchBar.selectedScopeButtonIndex) + search(matching: searchBar.text ?? "") } func searchBar(_: UISearchBar, textDidChange searchText: String) { @@ -431,6 +444,7 @@ extension PasswordNavigationViewController: UISearchBarDelegate { func cancelSearch() { configureTableView(in: parentPasswordEntity) dataSource?.isSearchActive = false + searchText = nil tableView.reloadData() } }