@@ -19,6 +19,7 @@ package com.duckduckgo.app.browser.omnibar
19
19
import android.content.Context
20
20
import android.graphics.Rect
21
21
import android.text.Editable
22
+ import android.text.Selection
22
23
import android.util.AttributeSet
23
24
import android.util.Patterns
24
25
import android.view.KeyEvent
@@ -35,24 +36,24 @@ class KeyboardAwareEditText : AppCompatEditText {
35
36
constructor (context: Context , attrs: AttributeSet ? ) : this (context, attrs, 0 )
36
37
constructor (context: Context , attrs: AttributeSet ? , defStyleAttr: Int ) : super (context, attrs, defStyleAttr)
37
38
38
- private var didFocusAlready = false
39
-
40
39
private fun Editable.isWebUrl (): Boolean {
41
40
return Patterns .WEB_URL .matcher(this .toString()).matches()
42
41
}
43
42
44
43
override fun onFocusChanged (focused : Boolean , direction : Int , previouslyFocusedRect : Rect ? ) {
45
44
super .onFocusChanged(focused, direction, previouslyFocusedRect)
46
- setSelectAllOnFocus(! didFocusAlready)
47
45
if (focused) {
48
- if (didFocusAlready && text != null && text?.isWebUrl() == false ) {
46
+ if (text != null && text?.isWebUrl() == false ) {
49
47
// trigger the text change listener so that we can show autocomplete
50
48
text = text
51
49
// cursor at the end of the word
52
50
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) }
53
55
}
54
56
showKeyboard()
55
- didFocusAlready = true
56
57
}
57
58
}
58
59
0 commit comments