Rudimentary autocomplete focus
This commit is contained in:
@@ -7,13 +7,29 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol URLBarDelegate: AnyObject
|
||||
{
|
||||
func urlBarRequestedFocusEscape(_ urlBar: URLBar)
|
||||
}
|
||||
|
||||
class TextFieldWithKeyCommands: UITextField
|
||||
{
|
||||
internal var _keyCommands: [UIKeyCommand]? = []
|
||||
override var keyCommands: [UIKeyCommand]? {
|
||||
get { _keyCommands }
|
||||
set { _keyCommands = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
class URLBar: ReliefButton
|
||||
{
|
||||
let textField = UITextField(frame: .zero)
|
||||
let textField = TextFieldWithKeyCommands(frame: .zero)
|
||||
let refreshButton = UIButton(frame: .zero)
|
||||
let errorButton = UIButton(frame: .zero)
|
||||
let documentButton = UIButton(frame: .zero)
|
||||
|
||||
weak var delegate: URLBarDelegate?
|
||||
|
||||
public enum LoadProgress {
|
||||
case complete
|
||||
case loading(progress: Double)
|
||||
@@ -57,6 +73,9 @@ class URLBar: ReliefButton
|
||||
// Mask view visibility is affected by editing state.
|
||||
self.layoutSubviews()
|
||||
}), for: [ .editingDidBegin, .editingDidEnd ])
|
||||
textField.keyCommands = [
|
||||
UIKeyCommand(action: #selector(Self.downKeyPressed), input: UIKeyCommand.inputDownArrow)
|
||||
]
|
||||
addSubview(textField)
|
||||
|
||||
textField.addAction(.init(handler: { [textField, refreshButton] _ in
|
||||
@@ -89,6 +108,11 @@ class URLBar: ReliefButton
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc
|
||||
private func downKeyPressed(_ sender: Any?) {
|
||||
self.delegate?.urlBarRequestedFocusEscape(self)
|
||||
}
|
||||
|
||||
private func updateProgressIndicator() {
|
||||
setErrorButtonAnimating(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user