Browser: Hold new tab to open links in new tab

This commit is contained in:
James Magahern
2021-02-15 22:56:20 -08:00
parent b4578d4978
commit a56c647a99

View File

@@ -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
}
let gestureRecognizer = UILongPressGestureRecognizer(action: newTabAction)
toolbarController.windowButton.addGestureRecognizer(gestureRecognizer)
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
}