Context menu support: starting with open in new tab
This commit is contained in:
@@ -364,6 +364,31 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
|
|||||||
return newTab.webView
|
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
|
// MARK: UITextField Delegate
|
||||||
|
|
||||||
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user