@@ -39,6 +39,8 @@ class KeyboardAwareEditText : AppCompatEditText {
3939 constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
4040 constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr)
4141
42+ private var didSelectQueryFirstTime = false
43+
4244 private fun Editable.isWebUrl (): Boolean {
4345 return Patterns .WEB_URL .matcher(this .toString()).matches()
4446 }
@@ -47,10 +49,15 @@ class KeyboardAwareEditText : AppCompatEditText {
4749 super .onFocusChanged(focused, direction, previouslyFocusedRect)
4850 if (focused) {
4951 if (text != null && text?.isWebUrl() == false ) {
50- // trigger the text change listener so that we can show autocomplete
51- text = text
52- // cursor at the end of the word
53- setSelection(text!! .length)
52+ if (didSelectQueryFirstTime) {
53+ // trigger the text change listener so that we can show autocomplete
54+ text = text
55+ // cursor at the end of the word
56+ setSelection(text!! .length)
57+ } else {
58+ didSelectQueryFirstTime = true
59+ post { Selection .selectAll(text) }
60+ }
5461 } else if (text?.isWebUrl() == true ) {
5562 // We always want URLs to be selected
5663 // we need to post for the selectAll to take effect. The wonders of Android layout !
0 commit comments