Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b63b02d

Browse files
committed
Only call when multiline, and update test to send correct inputtype
1 parent b595146 commit b63b02d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

shell/platform/android/io/flutter/plugin/editing/InputConnectionAdaptor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Build;
99
import android.text.DynamicLayout;
1010
import android.text.Editable;
11+
import android.text.InputType;
1112
import android.text.Layout;
1213
import android.text.Selection;
1314
import android.text.TextPaint;
@@ -221,12 +222,15 @@ public boolean sendKeyEvent(KeyEvent event) {
221222
int newSel = Math.min(selStart + 1, mEditable.length());
222223
setSelection(newSel, newSel);
223224
return true;
225+
// When the enter key is pressed on a non-multiline field, consider it a
226+
// submit instead of a newline.
227+
} else if ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER
228+
|| event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER)
229+
&& mEditorInfo.inputType != (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE)) {
230+
performEditorAction(mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION);
231+
return true;
224232
} else {
225233
// Enter a character.
226-
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
227-
|| event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_ENTER) {
228-
performEditorAction(mEditorInfo.imeOptions & EditorInfo.IME_MASK_ACTION);
229-
}
230234
int character = event.getUnicodeChar();
231235
if (character != 0) {
232236
int selStart = Math.max(0, Selection.getSelectionStart(mEditable));

shell/platform/android/test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.os.Build;
1818
import android.provider.Settings;
1919
import android.text.Editable;
20+
import android.text.InputType;
2021
import android.util.SparseIntArray;
2122
import android.view.KeyEvent;
2223
import android.view.View;
@@ -61,6 +62,7 @@ public void inputConnectionAdaptor_ReceivesEnter() throws NullPointerException {
6162
Editable mEditable = Editable.Factory.getInstance().newEditable("");
6263
Editable spyEditable = spy(mEditable);
6364
EditorInfo outAttrs = new EditorInfo();
65+
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
6466

6567
InputConnectionAdaptor inputConnectionAdaptor = new InputConnectionAdaptor(
6668
testView,

0 commit comments

Comments
 (0)