mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
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:
-6
@@ -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)
|
||||
|
||||
-1
@@ -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()
|
||||
|
||||
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user