Drop the comments from the Enter key handling

Review feedback: the callback name and the device-id check read on their
own, and the test names carry the soft versus physical keyboard rule.
This commit is contained in:
hayaksi1
2026-08-09 15:37:18 +03:00
parent 1024323661
commit 4b5429395d
3 changed files with 0 additions and 8 deletions
@@ -19,10 +19,6 @@ internal class MarkdownEditText(
) : AppCompatEditText(context) {
var onSelectionChangeListener: ((Int, Int) -> Unit)? = null
/**
* Invoked when Enter is pressed on a physical keyboard without Shift. Return true to consume the
* key, i.e. to send instead of inserting a newline.
*/
var onEnterKeyListener: (() -> Boolean)? = null
private var isModifyingText = false
@@ -30,13 +26,11 @@ internal class MarkdownEditText(
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (event.keyCode == KeyEvent.KEYCODE_ENTER &&
!event.isShiftPressed &&
// A soft keyboard must keep inserting a newline, only a real one sends.
event.deviceId != KeyCharacterMap.VIRTUAL_KEYBOARD
) {
val listener = onEnterKeyListener
if (listener != null) {
return when (event.action) {
// Consume the release too, so no newline leaks out on key repeat.
KeyEvent.ACTION_UP -> true
KeyEvent.ACTION_DOWN -> if (event.repeatCount == 0) listener() else true
else -> super.dispatchKeyEvent(event)
@@ -133,7 +133,6 @@ fun MarkdownTextInput(
update = { editText ->
editText.contentDescription = placeholder
editText.applyStyleInCompose(richTextEditorStyle)
// Set here rather than in the factory, which runs once and would capture a stale lambda.
editText.onEnterKeyListener = onSendMessage?.let { send ->
{
send()
@@ -233,7 +233,6 @@ class MarkdownTextInputTest : RobolectricTest() {
}
private companion object {
// Any device id other than KeyCharacterMap.VIRTUAL_KEYBOARD is a real keyboard.
const val PHYSICAL_KEYBOARD_DEVICE_ID = 1
}
}