diff --git a/app/src/main/java/com/duckduckgo/app/browser/omnibar/KeyboardAwareEditText.kt b/app/src/main/java/com/duckduckgo/app/browser/omnibar/KeyboardAwareEditText.kt index 64312e207a69..edfb2601ba02 100644 --- a/app/src/main/java/com/duckduckgo/app/browser/omnibar/KeyboardAwareEditText.kt +++ b/app/src/main/java/com/duckduckgo/app/browser/omnibar/KeyboardAwareEditText.kt @@ -19,6 +19,7 @@ package com.duckduckgo.app.browser.omnibar import android.content.Context import android.graphics.Rect import android.text.Editable +import android.text.Selection import android.util.AttributeSet import android.util.Patterns import android.view.KeyEvent @@ -35,24 +36,24 @@ class KeyboardAwareEditText : AppCompatEditText { constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - private var didFocusAlready = false - private fun Editable.isWebUrl(): Boolean { return Patterns.WEB_URL.matcher(this.toString()).matches() } override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) { super.onFocusChanged(focused, direction, previouslyFocusedRect) - setSelectAllOnFocus(!didFocusAlready) if (focused) { - if (didFocusAlready && text != null && text?.isWebUrl() == false) { + if (text != null && text?.isWebUrl() == false) { // trigger the text change listener so that we can show autocomplete text = text // cursor at the end of the word setSelection(text!!.length) + } else if (text?.isWebUrl() == true) { + // We always want URLs to be selected + // we need to post for the selectAll to take effect. The wonders of Android layout ! + post { Selection.selectAll(text) } } showKeyboard() - didFocusAlready = true } }