diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index eb53d38..5912ead 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -364,6 +364,31 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat return newTab.webView } + func webView(_ webView: WKWebView, contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo, completionHandler: @escaping (UIContextMenuConfiguration?) -> Void) { + let menuConfig = UIContextMenuConfiguration(identifier: nil, + previewProvider: nil) { (menuElements: [UIMenuElement]) -> UIMenu? in + + let openInNewTab = UIAction(title: "Open in New Tab", + image: UIImage(systemName: "plus.app"), + identifier: nil, + discoverabilityTitle: nil, + attributes: [], + state: .off) { [unowned self] _ in + let newTab = tabController.createNewTab(url: elementInfo.linkURL) + self.tab = newTab + } + + + return UIMenu(title: elementInfo.linkURL?.absoluteString ?? "Link", + image: nil, + identifier: nil, + options: .displayInline, + children: [ openInNewTab ] + menuElements) + } + + completionHandler(menuConfig) + } + // MARK: UITextField Delegate func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {