8000 Fixed search bar selection behavior (#1099) · libandroid/Android@8f46aa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f46aa7

Browse files
authored
Fixed search bar selection behavior (duckduckgo#1099)
* Fixed search bar selection behavior * Removed didFocusAlready
1 parent e3411fa commit 8f46aa7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.duckduckgo.app.browser.omnibar
1919
import android.content.Context
2020
import android.graphics.Rect
2121
import android.text.Editable
22+
import android.text.Selection
2223
import android.util.AttributeSet
2324
import android.util.Patterns
2425
import 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

Comments
 (0)
0