Shortcuts: close tab keyboard shortcut

This commit is contained in:
James Magahern
2020-11-10 11:57:40 -06:00
parent 5e0f1d252a
commit 9344e3c32d
3 changed files with 24 additions and 0 deletions

View File

@@ -59,6 +59,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
action: #selector(ShortcutResponder.previousTab) action: #selector(ShortcutResponder.previousTab)
), ),
// Close tab
UIKeyCommand(
modifiers: [.command], input: "W",
title: "Close Tab",
action: #selector(ShortcutResponder.closeTab)
),
// Next Tab // Next Tab
UIKeyCommand( UIKeyCommand(
modifiers: [.command, .shift], input: "]", modifiers: [.command, .shift], input: "]",

View File

@@ -597,6 +597,20 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
} }
} }
func closeTab(_ sender: Any?) {
if tabController.tabs.count > 1 {
tabController.closeTab(self.tab)
} else {
#if targetEnvironment(macCatalyst)
if let originWindowScene = self.view.window?.windowScene {
UIApplication.shared.requestSceneSessionDestruction(originWindowScene.session, options: nil) { error in
print("Error when requesting scene destruction: " + error.localizedDescription)
}
}
#endif
}
}
func findOnPage(_ sender: Any?) { func findOnPage(_ sender: Any?) {
browserView.setFindOnPageVisible(true, animated: true) browserView.setFindOnPageVisible(true, animated: true)
findOnPageController.findOnPageView.textField.becomeFirstResponder() findOnPageController.findOnPageView.textField.becomeFirstResponder()

View File

@@ -27,6 +27,9 @@ protocol ShortcutResponder: class {
@objc @objc
optional func nextTab(_ sender: Any?) optional func nextTab(_ sender: Any?)
@objc
optional func closeTab(_ sender: Any?)
@objc @objc
optional func findOnPage(_ sender: Any?) optional func findOnPage(_ sender: Any?)
} }