diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index 9545878..7bf3e66 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -496,6 +496,25 @@ class BrowserViewController: UIViewController toolbarController.urlBar.textField.resignFirstResponder() } + override func target(forAction action: Selector, withSender sender: Any?) -> Any? { + var findActions: [Selector] = [] + if #available(macCatalyst 16.0, *) { + findActions = [ + #selector(UIResponder.find(_:)), + #selector(UIResponder.findNext(_:)), + #selector(UIResponder.findPrevious(_:)), + #selector(UIResponder.findAndReplace(_:)), + #selector(UIResponder.useSelectionForFind(_:)), + ] + } + + if findActions.contains(where: { $0 == action }) { + return webView.target(forAction: action, withSender: sender) + } + + return super.target(forAction: action, withSender: sender) + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) becomeFirstResponder() diff --git a/App/KeyboardShortcuts.swift b/App/KeyboardShortcuts.swift index 0e92371..60a38ac 100644 --- a/App/KeyboardShortcuts.swift +++ b/App/KeyboardShortcuts.swift @@ -49,6 +49,15 @@ protocol ShortcutResponder: AnyObject { optional func toggleDarkMode(_ sender: Any?) } +fileprivate extension Array { + func removeNulls() -> Array { + self.filter { element in + guard let keyCommand = element as? UIKeyCommand else { return true } + return !keyCommand.isNull() + } + } +} + public class KeyboardShortcuts { public enum Category: CaseIterable { case application @@ -121,7 +130,7 @@ public class KeyboardShortcuts { action: #selector(ShortcutResponder.stop) ) ]), - ] + ].removeNulls() case .go: return [ diff --git a/App/Utilities/UIKeyCommand+ConvInit.swift b/App/Utilities/UIKeyCommand+ConvInit.swift index c9fe449..ba9f040 100644 --- a/App/Utilities/UIKeyCommand+ConvInit.swift +++ b/App/Utilities/UIKeyCommand+ConvInit.swift @@ -16,6 +16,10 @@ extension UIKeyCommand { UIKeyCommand(modifiers: [], input: "", title: "", action: #selector(_null)) } + public func isNull() -> Bool { + return action == #selector(_null) + } + convenience init(modifiers: UIKeyModifierFlags, input: String, title: String, action: Selector) { self.init(input: input, modifierFlags: modifiers, action: action) self.title = title