diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index 7e3b45a..9b3a048 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -211,7 +211,8 @@ class OnboardingSearchController: NSViewController { appName.stringValue = "Quick Add Locations".localized() onboardingTypeLabel.stringValue = "More search options in Clocker Preferences.".localized() setInfoLabel(CLEmptyString) - searchBar.placeholderString = "Enter 3 or more characters for locations you'll like to add".localized() + searchBar.placeholderString = "Press Enter to Search!" + searchBar.delegate = self resultsTableView.backgroundColor = Themer.shared().mainBackgroundColor() resultsTableView.enclosingScrollView?.backgroundColor = Themer.shared().mainBackgroundColor() @@ -243,7 +244,14 @@ class OnboardingSearchController: NSViewController { } NSObject.cancelPreviousPerformRequests(withTarget: self) - perform(#selector(OnboardingSearchController.actualSearch), with: nil, afterDelay: 0.5) + perform(#selector(OnboardingSearchController.actualSearch), with: nil, afterDelay: 0.2) + } + + fileprivate func resetIfNeccesary(_ searchString: String) { + if searchString.isEmpty { + resetSearchView() + setInfoLabel(CLEmptyString) + } } @objc func actualSearch() { @@ -260,6 +268,7 @@ class OnboardingSearchController: NSViewController { searchString = words.joined(separator: CLEmptyString) if searchString.count < 3 { + resetIfNeccesary(searchString) return } @@ -403,3 +412,24 @@ class ResultSectionHeaderTableViewCell: NSTableCellView { class ResultTableViewCell: NSTableCellView { @IBOutlet var result: NSTextField! } + +extension OnboardingSearchController: NSSearchFieldDelegate { + func control(_ control: NSControl, textView _: NSTextView, doCommandBy commandSelector: Selector) -> Bool { + guard let searchField = control as? NSSearchField else { + return false + } + + if commandSelector == #selector(NSResponder.insertNewline(_:)) { + self.search(searchField) + return true + } else if commandSelector == #selector(NSResponder.deleteForward(_:)) || commandSelector == #selector(NSResponder.deleteBackward(_:)) { + // Handle DELETE key + self.search(searchField) + return false + } + + print("Not Handled") + // return true if the action was handled; otherwise false + return false + } +} diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index d63c33d..384a3b0 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -597,7 +597,7 @@ extension PreferencesViewController { } private func installTimezone(_ timezone: Timezone) { - guard let dataObject = self.searchResultsDataSource.filteredArray[self.availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { + guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { assertionFailure("Data was unexpectedly nil") return }