Browser: command+click to open things in new tabs. Uses LLKB!
This commit is contained in:
@@ -38,6 +38,8 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
|
||||
private var loadError: Error?
|
||||
|
||||
private var commandKeyHeld: Bool = false
|
||||
|
||||
override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent }
|
||||
|
||||
init() {
|
||||
@@ -324,6 +326,32 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
toolbarController.traitCollectionDidChange(previousTraitCollection)
|
||||
}
|
||||
|
||||
private func updateCommandKeyState(forPresses presses: Set<UIPress>) {
|
||||
guard let press = presses.first else { return }
|
||||
|
||||
if let key = press.key {
|
||||
if key.modifierFlags == [.command] {
|
||||
let isDown = press.phase == .began || press.phase == .changed || press.phase == .stationary
|
||||
self.commandKeyHeld = isDown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
|
||||
super.pressesBegan(presses, with: event)
|
||||
updateCommandKeyState(forPresses: presses)
|
||||
}
|
||||
|
||||
override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
|
||||
super.pressesCancelled(presses, with: event)
|
||||
updateCommandKeyState(forPresses: presses)
|
||||
}
|
||||
|
||||
override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
|
||||
super.pressesEnded(presses, with: event)
|
||||
updateCommandKeyState(forPresses: presses)
|
||||
}
|
||||
|
||||
private func updateScriptBlockerButton() {
|
||||
var numBlockedScripts: Int = tab.blockedScriptOrigins.count
|
||||
if tab.url != nil, tab.javaScriptEnabled == false {
|
||||
@@ -411,6 +439,21 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
|
||||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void)
|
||||
{
|
||||
// Handle command+click
|
||||
if commandKeyHeld {
|
||||
// Cancel navigation in this tab
|
||||
decisionHandler(.cancel, preferences)
|
||||
|
||||
// Start navigation in a new tab
|
||||
let tab = tabController.createNewTab(url: navigationAction.request.url)
|
||||
self.tab = tab
|
||||
|
||||
// Reset this flag.
|
||||
commandKeyHeld = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var allowJavaScript = tab.javaScriptEnabled
|
||||
if !allowJavaScript, let host = navigationAction.request.url?.host {
|
||||
// Check origin policy
|
||||
|
||||
Reference in New Issue
Block a user