Add menu command and keyboard shortcut to move focus to the search field.

This commit is contained in:
Brent Simmons 2019-02-24 23:03:32 -08:00
parent 315af1ef7f
commit e0c7f8737b
2 changed files with 18 additions and 7 deletions

View File

@ -157,17 +157,18 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Find" id="1b7-l0-nxx">
<items>
<menuItem title="Article Search" keyEquivalent="f" id="nB2-mv-2i5">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="moveFocusToSearchField:" target="Ady-hI-5gd" id="MhU-Pb-Po8"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="QuB-t0-74E"/>
<menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
<connections>
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="cD7-Qs-BN4"/>
</connections>
</menuItem>
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="WD3-Gg-5AJ"/>
</connections>
</menuItem>
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
<connections>
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="NDo-RZ-v9R"/>
@ -178,6 +179,7 @@
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="HOh-sY-3ay"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="fQa-bL-eze"/>
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
<connections>
<action selector="performFindPanelAction:" target="Ady-hI-5gd" id="U76-nv-p5D"/>

View File

@ -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