From e0c7f8737bd44296f9e55a2ded1b90bc3f954aac Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 24 Feb 2019 23:03:32 -0800 Subject: [PATCH] Add menu command and keyboard shortcut to move focus to the search field. --- NetNewsWire/Base.lproj/Main.storyboard | 14 ++++++++------ NetNewsWire/MainWindow/MainWindowController.swift | 11 ++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/NetNewsWire/Base.lproj/Main.storyboard b/NetNewsWire/Base.lproj/Main.storyboard index 8043ab3cc..94caf875c 100644 --- a/NetNewsWire/Base.lproj/Main.storyboard +++ b/NetNewsWire/Base.lproj/Main.storyboard @@ -157,17 +157,18 @@ + + + + + + + - - - - - - @@ -178,6 +179,7 @@ + diff --git a/NetNewsWire/MainWindow/MainWindowController.swift b/NetNewsWire/MainWindow/MainWindowController.swift index a8aa71b29..6ddc8dfe3 100644 --- a/NetNewsWire/MainWindow/MainWindowController.swift +++ b/NetNewsWire/MainWindow/MainWindowController.swift @@ -195,8 +195,11 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations, NSW return canShowShareMenu() } - if item.action == #selector(toggleSidebar(_:)) { + if item.action == #selector(moveFocusToSearchField(_:)) { + return currentSearchField != nil + } + if item.action == #selector(toggleSidebar(_:)) { guard let splitViewItem = sidebarSplitViewItem else { return false } @@ -354,6 +357,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations, NSW sharingServicePicker.show(relativeTo: view.bounds, of: view, preferredEdge: .minY) } + @IBAction func moveFocusToSearchField(_ sender: Any?) { + guard let searchField = currentSearchField else { + return + } + window?.makeFirstResponder(searchField) + } } // MARK: - SidebarDelegate