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

Conversation

@jason-simmons
Copy link
Member

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.

@DeMonkeyCoder
Copy link
Contributor

DeMonkeyCoder commented Apr 30, 2020

It has problems with non-spacing marks as I mentioned
#17960 (comment)
See my PR's test and:
http://unicode.org/L2/L2005/05134-nonspacing-pos.html

But your code is working well with tests and I'm trying to fix my code based on yours.

Copy link
Member

@gaaclarke gaaclarke left a 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);
}
};
Copy link
Member

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?

Copy link
Member Author

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,
Copy link
Member

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?

Copy link
Member Author

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(
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@gaaclarke gaaclarke Apr 30, 2020

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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants