From 38cd519b7c73a69cd6c768f84bba35abc171a76d Mon Sep 17 00:00:00 2001 From: Joe Gasiorek Date: Tue, 26 Sep 2017 22:25:13 -0700 Subject: [PATCH] Add iPad keyboard shortcuts (#499) --- Blockzilla/BrowserViewController.swift | 25 +++++++++++++++++++++++++ Blockzilla/UIConstants.swift | 1 + 2 files changed, 26 insertions(+) diff --git a/Blockzilla/BrowserViewController.swift b/Blockzilla/BrowserViewController.swift index e9ae06325b..077d91b3cc 100644 --- a/Blockzilla/BrowserViewController.swift +++ b/Blockzilla/BrowserViewController.swift @@ -328,6 +328,31 @@ class BrowserViewController: UIViewController { alertController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.size.width / 2.0, y: self.view.bounds.size.height / 2.0, width: 1.0, height: 1.0) present(alertController, animated: true, completion: nil) } + + @objc private func selectLocationBar() { + urlBar.becomeFirstResponder() + } + + @objc private func reload() { + browser.reload() + } + + @objc private func goBack() { + browser.goBack() + } + + @objc private func goForward() { + browser.goForward() + } + + override var keyCommands: [UIKeyCommand]? { + return [ + UIKeyCommand(input: "l", modifierFlags: .command, action: #selector(BrowserViewController.selectLocationBar), discoverabilityTitle: UIConstants.strings.selectLocationBarTitle), + UIKeyCommand(input: "r", modifierFlags: .command, action: #selector(BrowserViewController.reload), discoverabilityTitle: UIConstants.strings.browserReload), + UIKeyCommand(input: "[", modifierFlags: .command, action: #selector(BrowserViewController.goBack), discoverabilityTitle: UIConstants.strings.browserBack), + UIKeyCommand(input: "]", modifierFlags: .command, action: #selector(BrowserViewController.goForward), discoverabilityTitle: UIConstants.strings.browserForward), + ] + } } extension BrowserViewController: URLBarDelegate { diff --git a/Blockzilla/UIConstants.swift b/Blockzilla/UIConstants.swift index 0606fa0021..728da56f4e 100644 --- a/Blockzilla/UIConstants.swift +++ b/Blockzilla/UIConstants.swift @@ -200,5 +200,6 @@ struct UIConstants { static let analyticTrackerLabel = NSLocalizedString("trackingProtection.analyticTrackerLabel", value: "Analytic trackers", comment: "label for analytic trackers.") static let socialTrackerLabel = NSLocalizedString("trackingProtection.socialTrackerLabel", value: "Social trackers", comment: "label for social trackers.") static let contentTrackerLabel = NSLocalizedString("trackingProtection.contentTrackerLabel", value: "Content trackers", comment: "label for content trackers.") + static let selectLocationBarTitle = NSLocalizedString("browserShortcutDescription.selectLocationBar", value: "Select Location Bar", comment: "Label to display in the Discoverability overlay for keyboard shortcuts") } }