mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-26 17:47:40 +00:00
search google if an unqualified url is entered
This commit is contained in:
parent
27077f1f8c
commit
267fbdd6c0
1 changed files with 16 additions and 2 deletions
|
|
@ -179,8 +179,16 @@ class WebBrowserViewController: UIViewController, UIWebViewDelegate, UIAlertView
|
|||
}
|
||||
|
||||
@objc func loadAddress(_ sender: Any, event: UIEvent) {
|
||||
guard let urlString = addressField?.text, var url = URL(string: urlString) else {
|
||||
log.debug("Attempting to load invalid URL: \(addressField?.text ?? "nil")")
|
||||
if let urlString = addressField?.text {
|
||||
loadUrlString(urlString)
|
||||
}
|
||||
}
|
||||
|
||||
func loadUrlString(_ urlString: String, allowSearchRedirect: Bool = true) {
|
||||
guard var url = URL(string: urlString) else {
|
||||
if allowSearchRedirect {
|
||||
loadSearchString(urlString)
|
||||
}
|
||||
return
|
||||
}
|
||||
if url.scheme == nil {
|
||||
|
|
@ -189,6 +197,12 @@ class WebBrowserViewController: UIViewController, UIWebViewDelegate, UIAlertView
|
|||
let request = URLRequest(url: url)
|
||||
webView.loadRequest(request)
|
||||
}
|
||||
|
||||
func loadSearchString(_ searchString: String) {
|
||||
if let query = searchString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
||||
loadUrlString("google.com/search?q=\(query)", allowSearchRedirect: false)
|
||||
}
|
||||
}
|
||||
|
||||
func updateAddress(_ request: URLRequest) {
|
||||
let url: URL? = request.mainDocumentURL
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue