-
Notifications
You must be signed in to change notification settings - Fork 6k
Handle backspace on Android by using the engine's ICU grapheme breaker #18041
Conversation
|
It has problems with non-spacing marks as I mentioned But your code is working well with tests and I'm trying to fix my code based on yours. |
gaaclarke
left a comment
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.
Code is looking good, @GaryQian knows more about the wisdom of doing this. Thanks!
| public int getOffsetBefore(String text, int offset) { | ||
| return FlutterJNI.nativeGetTextOffsetBefore(text, offset); | ||
| } | ||
| }; |
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.
nit: Don't we have access to lambdas?
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.
AFAIK the Android embedding does not use lambdas. The embedding supports Android versions back to API 16 and tries to avoid anything that would make it more difficult to support legacy toolchains and runtimes.
| ); | ||
| } | ||
|
|
||
| static jint GetTextOffsetBefore(JNIEnv* env, |
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.
Can you add a tiny docstring for this function?
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.
done
| int selStart = 29; | ||
| Editable editable = sampleRtlEditable(selStart, selStart); | ||
| InputConnectionAdaptor adaptor = sampleInputConnectionAdaptor(editable); | ||
| adaptor.setGetOffsetBefore( |
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 seems to just adjust an old test, where is the test that exercises the new logic?
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 a reimplementation of InputConnectionAdaptor delete key handling that uses a JNI function instead of an Android system API to find the character boundary. Unfortunately the new part is JNI native code, and I don't think the embedding has infrastructure for testing that. The Robolectric tests do not load the engine native code library.
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've looked into this in the past, let me try to remember. There are 2 ways you can make unit tests, robolectric or a slower test that runs on an emulator. Robolectric can load JNI but your JNI library has to be compiled for the desktop operating system, which might be easy or near impossible depending on what you are doing. It's near impossible if you are calling native android libraries.
The backspace key handler in the Android text input plugin needs to identify the logical character preceding the cursor and remove it from the editable. Older versions of Android may not provide APIs that can do this with accurate handling of current emojis. This implementation handles it by invoking the icu::BreakIterator via JNI.
0cb2808 to
b81be9b
Compare
The backspace key handler in the Android text input plugin needs to
identify the logical character preceding the cursor and remove it
from the editable. Older versions of Android may not provide APIs
that can do this with accurate handling of current emojis. This
implementation handles it by invoking the icu::BreakIterator via JNI.