Rudimentary autocomplete focus

This commit is contained in:
James Magahern
2021-03-09 00:14:48 -08:00
parent b550868b50
commit 80a897ece6
3 changed files with 42 additions and 2 deletions

View File

@@ -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)