This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
io/flutter/plugin/editing
test/io/flutter/plugin/editing Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 88import android .os .Build ;
99import android .text .DynamicLayout ;
1010import android .text .Editable ;
11+ import android .text .InputType ;
1112import android .text .Layout ;
1213import android .text .Selection ;
1314import 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 ));
Original file line number Diff line number Diff line change 1717import android .os .Build ;
1818import android .provider .Settings ;
1919import android .text .Editable ;
20+ import android .text .InputType ;
2021import android .util .SparseIntArray ;
2122import android .view .KeyEvent ;
2223import 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 ,
You can’t perform that action at this time.
0 commit comments