Keyboard shortcuts

This commit is contained in:
James Magahern
2020-09-21 18:35:39 -07:00
parent 14a28a0776
commit e934a4d3f5
5 changed files with 138 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ import UniformTypeIdentifiers
class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegate,
UITextFieldDelegate, ScriptPolicyViewControllerDelegate,
UIPopoverPresentationControllerDelegate, TabDelegate, TabPickerViewControllerDelegate,
AutocompleteViewControllerDelegate
AutocompleteViewControllerDelegate, ShortcutResponder
{
let browserView = BrowserView()
var tab: Tab { didSet { didChangeTab(tab) } }
@@ -428,4 +428,39 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
tab.beginLoadingURL(item.url)
autocompleteViewController.view.isHidden = true
}
// MARK: Keyboard shortcuts
func focusURLBar(_ sender: Any?) {
toolbarController.urlBar.textField.becomeFirstResponder()
}
func goBack(_ sender: Any?) {
tab.webView.goBack()
}
func goForward(_ sender: Any?) {
tab.webView.goForward()
}
func createTab(_ sender: Any?) {
let newTab = tabController.createNewTab(url: nil)
self.tab = newTab
}
func previousTab(_ sender: Any?) {
if let tabIndex = tabController.tabs.firstIndex(of: self.tab) {
if tabIndex - 1 >= 0 {
self.tab = tabController.tabs[tabIndex - 1]
}
}
}
func nextTab(_ sender: Any?) {
if let tabIndex = tabController.tabs.firstIndex(of: self.tab) {
if tabIndex + 1 < tabController.tabs.count {
self.tab = tabController.tabs[tabIndex + 1]
}
}
}
}