Skip to content

Commit 4738421

Browse files
authored
Fixed regression query selection on search bar (#1116)
1 parent ef561c4 commit 4738421

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/src/main/java/com/duckduckgo/app/browser/omnibar/KeyboardAwareEditText.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)