     func webView(_ webView: WKWebView,
                  decidePolicyFor navigationAction: WKNavigationAction,
                  decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
-        
-        guard navigationAction.buttonNumber <= 1 else {
-            if let url = navigationAction.request.url {
-                Swift.print("newWindow with url:\(String(describing: url))")
-                self.appDelegate.openURLInNewWindow(url)
-            }
+        var url = navigationAction.request.url!
+        
+        guard navigationAction.buttonNumber < 2 else {
+            Swift.print("newWindow with url:\(String(describing: url))")
+            self.appDelegate.openURLInNewWindow(url)
             decisionHandler(WKNavigationActionPolicy.cancel)
             return
         }
         
-        guard !UserSettings.disabledMagicURLs.value,
-            let url = navigationAction.request.url,
-            !((navigationAction.request.url?.absoluteString.hasPrefix("file://"))!) else {
-                if let myWebView: MyWebView = webView as? MyWebView, NSApp.currentEvent?.buttonNumber == 2, let url = myWebView.selectedURL {
-                    Swift.print("newWindow with url:\(url)")
-                    appDelegate.openURLInNewWindow(url)
- //                   webView.goBack()
-                    decisionHandler(WKNavigationActionPolicy.cancel)
-                }
-                else
-                {
-                    decisionHandler(WKNavigationActionPolicy.allow)
-                }
-                return
-        }
-
-        if let newUrl = UrlHelpers.doMagic(url) {
+        guard !UserSettings.disabledMagicURLs.value else {
+            if let selectedURL = (webView as! MyWebView).selectedURL {
+                url = selectedURL
+            }
+            if navigationAction.buttonNumber > 1 {
+                appDelegate.openURLInNewWindow(url)
+                decisionHandler(WKNavigationActionPolicy.cancel)
+            }
+            else
+            {
+                decisionHandler(WKNavigationActionPolicy.allow)
+            }
+            return
+        }
+
+        if let newUrl = UrlHelpers.doMagic(url), newUrl != url {
             decisionHandler(WKNavigationActionPolicy.cancel)
-            loadURL(url: newUrl)
+            if let selectedURL = (webView as! MyWebView).selectedURL {
+                url = selectedURL
+            }
+            if navigationAction.buttonNumber > 1
+            {
+                appDelegate.openURLInNewWindow(newUrl)
+            }
+            else
+            {
+                loadURL(url: newUrl)
+            }
         } else {
             decisionHandler(WKNavigationActionPolicy.allow)
         }

                    
                    hpc.webViewController.webView = newView
                    contentView.addSubview(newView)
                    wvc.viewDidLoad()

                    hpc.webViewController.loadURL(text: newURL.absoluteString)
                    newView.navigationDelegate = wvc
                    newView.uiDelegate = wvc
                    newWebView = hpc.webView
                    
                    //  Setups all done, make us visible
                    window.makeKeyAndOrderFront(self)
                }
            } catch let error {
                NSApp.presentError(error)
            }
        }
        if UserSettings.createNewWindows.value != newWindows {
            UserSettings.createNewWindows.value = newWindows
        }

        return newWebView

    func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration,
                 for navigationAction: WKNavigationAction,
                 windowFeatures: WKWindowFeatures) -> WKWebView? {

        if navigationAction.targetFrame == nil {
            appDelegate.openURLInNewWindow(navigationAction.request.url!)
            return nil
        }
        
        //  We really want to use the supplied config, so use custom setup
        var newWebView : WKWebView?
        Swift.print("createWebViewWith")
        
        if let newURL = navigationAction.request.url {
            do {
                let doc = try NSDocumentController.shared().makeDocument(withContentsOf: newURL, ofType: "Custom")
                if let hpc = doc.windowControllers.first as? HeliumPanelController,
