Browser: Hold new tab to open links in new tab
This commit is contained in:
@@ -40,6 +40,12 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
private var loadError: Error?
|
||||
|
||||
private var commandKeyHeld: Bool = false
|
||||
private var windowButtonHeld: Bool {
|
||||
get { toolbarController.newTabButton.isTracking }
|
||||
set { toolbarController.newTabButton.cancelTracking(with: nil) }
|
||||
}
|
||||
|
||||
static let longPressWindowButtonToMakeNewTab: Bool = false
|
||||
|
||||
private var darkModeEnabled: Bool {
|
||||
get { tab.bridge.darkModeEnabled }
|
||||
@@ -159,8 +165,12 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
self.tab = newTab
|
||||
}
|
||||
|
||||
if Self.longPressWindowButtonToMakeNewTab {
|
||||
// Long press window button to make new tab?
|
||||
|
||||
let gestureRecognizer = UILongPressGestureRecognizer(action: newTabAction)
|
||||
toolbarController.windowButton.addGestureRecognizer(gestureRecognizer)
|
||||
}
|
||||
|
||||
// New tab button
|
||||
toolbarController.newTabButton.addAction(newTabAction, for: .touchUpInside)
|
||||
@@ -508,7 +518,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void)
|
||||
{
|
||||
// Handle command+click
|
||||
if commandKeyHeld && navigationAction.navigationType == .linkActivated {
|
||||
if (commandKeyHeld || windowButtonHeld) && navigationAction.navigationType == .linkActivated {
|
||||
// Cancel navigation in this tab
|
||||
decisionHandler(.cancel, preferences)
|
||||
|
||||
@@ -518,6 +528,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
||||
|
||||
// Reset this flag.
|
||||
commandKeyHeld = false
|
||||
windowButtonHeld = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user