@@ -19,6 +19,7 @@ package com.duckduckgo.app.browser.omnibar
1919import android.content.Context
2020import android.graphics.Rect
2121import android.text.Editable
22+ import android.text.Selection
2223import android.util.AttributeSet
2324import android.util.Patterns
2425import android.view.KeyEvent
@@ -35,24 +36,24 @@ class KeyboardAwareEditText : AppCompatEditText {
3536 constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
3637 constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr)
3738
38- private var didFocusAlready = false
39-
4039 private fun Editable.isWebUrl (): Boolean {
4140 return Patterns .WEB_URL .matcher(this .toString()).matches()
4241 }
4342
4443 override fun onFocusChanged (focused : Boolean , direction : Int , previouslyFocusedRect : Rect ? ) {
4544 super .onFocusChanged(focused, direction, previouslyFocusedRect)
46- setSelectAllOnFocus(! didFocusAlready)
4745 if (focused) {
48- if (didFocusAlready && text != null && text?.isWebUrl() == false ) {
46+ if (text != null && text?.isWebUrl() == false ) {
4947 // trigger the text change listener so that we can show autocomplete
5048 text = text
5149 // cursor at the end of the word
5250 setSelection(text!! .length)
51+ } else if (text?.isWebUrl() == true ) {
52+ // We always want URLs to be selected
53+ // we need to post for the selectAll to take effect. The wonders of Android layout !
54+ post { Selection .selectAll(text) }
5355 }
5456 showKeyboard()
55- didFocusAlready = true
5657 }
5758 }
5859
0 commit comments