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