Skip to content

Commit 998cfcf

Browse files
committed
fix(emoji): hide the backspace button while the search field is focused
With the keyboard open for typing a search term, a backspace button right next to the field read as if it deleted from the search term itself rather than from the host's own text field. EmojiPickerPanel now hides it on search-field focus and restores it once focus leaves (or the panel is reset). Assisted-by: Claude Code:claude-sonnet-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent 0df5368 commit 998cfcf

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

app/src/main/java/com/nextcloud/talk/emojipicker/EmojiPickerPanel.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class EmojiPickerPanel @JvmOverloads constructor(
4444
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
4545
private var searchJob: Job? = null
4646
private var recentEmojiProvider: RecentEmojiProvider? = null
47+
private var searchFieldFocused = false
4748

4849
var searchEnabled: Boolean = true
4950
set(value) {
@@ -55,7 +56,7 @@ class EmojiPickerPanel @JvmOverloads constructor(
5556
var backspaceEnabled: Boolean = false
5657
set(value) {
5758
field = value
58-
binding.emojiBackspaceButton.isVisible = value
59+
updateBackspaceVisibility()
5960
updateSearchRowVisibility()
6061
}
6162

@@ -67,11 +68,15 @@ class EmojiPickerPanel @JvmOverloads constructor(
6768
init {
6869
orientation = VERTICAL
6970
binding.emojiSearchFieldGroup.isVisible = searchEnabled
70-
binding.emojiBackspaceButton.isVisible = backspaceEnabled
71+
updateBackspaceVisibility()
7172
updateSearchRowVisibility()
7273

7374
binding.emojiPicker.setOnEmojiPickedListener { item -> onEmojiPicked?.invoke(item.emoji) }
7475
binding.emojiSearchInput.doAfterTextChanged { editable -> onSearchTextChanged(editable?.toString().orEmpty()) }
76+
binding.emojiSearchInput.setOnFocusChangeListener { _, hasFocus ->
77+
searchFieldFocused = hasFocus
78+
updateBackspaceVisibility()
79+
}
7580
binding.emojiSearchClear.setOnClickListener { binding.emojiSearchInput.setText("") }
7681
binding.emojiBackspaceButton.setOnClickListener { onBackspaceClicked?.invoke() }
7782
}
@@ -90,6 +95,7 @@ class EmojiPickerPanel @JvmOverloads constructor(
9095
fun reset() {
9196
searchJob?.cancel()
9297
binding.emojiSearchInput.setText("")
98+
binding.emojiSearchInput.clearFocus()
9399
showGrid()
94100
}
95101

@@ -122,6 +128,15 @@ class EmojiPickerPanel @JvmOverloads constructor(
122128
binding.emojiSearchRow.isVisible = searchEnabled || backspaceEnabled
123129
}
124130

131+
/**
132+
* Hidden while the search field has focus - with the keyboard open for typing a search
133+
* term, a backspace button right next to it reads as belonging to the search field rather
134+
* than to whatever text field the host's own [onBackspaceClicked] actually edits.
135+
*/
136+
private fun updateBackspaceVisibility() {
137+
binding.emojiBackspaceButton.isVisible = backspaceEnabled && !searchFieldFocused
138+
}
139+
125140
private fun onSearchTextChanged(query: String) {
126141
binding.emojiSearchClear.isVisible = query.isNotEmpty()
127142
searchJob?.cancel()

0 commit comments

Comments
 (0)