diff --git a/App/AppDelegate.swift b/App/AppDelegate.swift index 3621364..98f8330 100644 --- a/App/AppDelegate.swift +++ b/App/AppDelegate.swift @@ -59,6 +59,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { action: #selector(ShortcutResponder.previousTab) ), + // Close tab + UIKeyCommand( + modifiers: [.command], input: "W", + title: "Close Tab", + action: #selector(ShortcutResponder.closeTab) + ), + // Next Tab UIKeyCommand( modifiers: [.command, .shift], input: "]", diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index b806f4b..f74c864 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -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?) { browserView.setFindOnPageVisible(true, animated: true) findOnPageController.findOnPageView.textField.becomeFirstResponder() diff --git a/App/KeyboardShortcuts.swift b/App/KeyboardShortcuts.swift index 7fef358..1d00c75 100644 --- a/App/KeyboardShortcuts.swift +++ b/App/KeyboardShortcuts.swift @@ -27,6 +27,9 @@ protocol ShortcutResponder: class { @objc optional func nextTab(_ sender: Any?) + @objc + optional func closeTab(_ sender: Any?) + @objc optional func findOnPage(_ sender: Any?) }