-
Notifications
You must be signed in to change notification settings - Fork 6k
Android Input Failed When TextInputType Is Phone, Number #31586
Android Input Failed When TextInputType Is Phone, Number #31586
Conversation
1a7af62 to
6412d4e
Compare
6412d4e to
8c77cbc
Compare
| final int selStart = Selection.getSelectionStart(mEditable); | ||
| final int selEnd = Selection.getSelectionEnd(mEditable); | ||
| final int character = event.getUnicodeChar(); | ||
| if (selStart < 0 || selEnd < 0 || character == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this case valid now, or just not possible because of the KEYCODE_DEL case above?
|
|
||
| final int selMin = Math.min(selStart, selEnd); | ||
| final int selMax = Math.max(selStart, selEnd); | ||
| final int selMin = Math.max(Math.min(selStart, selEnd), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
related to the question above, when is selStart or selEnd < 0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this issue case, the user use an TextInputConfiguration to connect the keyboard, but not use TextFiled, when the keyboard is number it will go to the handleKeyEvent method and cause is input a number then in to the else branch in this case the selStart and selEnd will < 0 that cause the bug
| final int selMin = Math.max(Math.min(selStart, selEnd), 0); | ||
| final int selMax = Math.max(Math.max(selStart, selEnd), 0); | ||
| beginBatchEdit(); | ||
| if (selMin != selMax) mEditable.delete(selMin, selMax); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this case still relevant?
| return handleVerticalMovement(false, event.isShiftPressed()); | ||
| // When the enter key is pressed on a non-multiline field, consider it a | ||
| // submit instead of a newline. | ||
| } else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the delete key not working? I think it's currently handled by the framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the delete key not working in this case flutter/flutter#98352, you can use the simple code to verify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use this demo, the framework doesn't handle the case of use input delete event. And in the engine doesn't handle it also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is meant to be handled by the framework code here: https://github.com/flutter/flutter/blob/ffe64c6336bfb0ad68436af904e6e1f28724dd5f/packages/flutter/lib/src/widgets/default_text_editing_shortcuts.dart#L165-L174
Could you elaborate a bit on why the framework isn't handling it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we use TextFiled widget that will make overridable in here https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/editable_text.dart#L3120 and when we input Delete that will handle in method handleKaypress: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/shortcuts.dart#L717, and the action https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/shortcuts.dart#L723 will be a instance of _OverridableContextAction<Intent>
But in this case, customer doesn't use TextFiled, only use a TextInputConfigure, when you input delete, the handleKaypress action will be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see what you're saying. The sample code provided doesn't make use of EditableText and implements TextInputClient instead. However this is not recommended as most text editing key bindings should be handled by the framework (text layout isn't available to the engine so text input plugin can't reliably handle deleting to the beginning of the line reliably, for example), and I'm hoping that we can remove/deprecate this handleKeyEvent method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, do you mean that the problem is caused by the way the example is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ideally the delete action needs to be handled by dart code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If delete the handleKey of Delete the user can't delete character. And do you have some suggestion to hold the delete character behavior?
| InputConnectionAdaptor adaptor = sampleInputConnectionAdaptor(editable); | ||
|
|
||
| KeyEvent downKeyDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL); | ||
| KeyEvent downKeyUP = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was added by @gspencergoog in #22626.
Is this change correct, Greg?
|
I think there is an open question for @LongCatIsLooong |
|
From PR review triage: There are open questions for @JsouLiang and @gspencergoog |
|
@JsouLiang Hi there again from PR triage. Are you interested in continuing with this PR? If so, it looks like there are some open questions for you. Thanks! |
|
@zanderso hey, yes i am interested in continuing with this PR, but i have some problems need to ask @LongCatIsLooong. Thanks. |
|
cc @LongCatIsLooong Are you able to reply to @JsouLiang query? |
|
Sorry for the delayed reply. @JsouLiang looks like the |
|
Is this any update? I still met this issue on android with Flutter v3.7.12 |
Fix Issue: 98352
In current case is not
cursor selectorbut current logic number input is will check theSelectionrangeWhen the
TextInputTypeisNumber, and you input text, the keyboard willsendKeyEvent, and next entry thehandleKeyEventmethodWhen first number entry this method the
selStartandselEndwill be-1, because there is no cursor and thus the Selection.start is not attach. ThegetSelectionStartwill return -1We need to support logic that without a cursor, and need support delete action.
Pre-launch Checklist
writing and running engine tests.
///).