Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down