Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sending generated character with key events. #7722

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.Map;

import android.view.KeyCharacterMap;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.JSONMessageCodec;
Expand All @@ -22,6 +23,8 @@ public class KeyEventChannel {
@NonNull
public final BasicMessageChannel<Object> channel;

private int mCombiningCharacter;

public KeyEventChannel(@NonNull DartExecutor dartExecutor) {
this.channel = new BasicMessageChannel<>(dartExecutor, "flutter/keyevent", JSONMessageCodec.INSTANCE);
}
Expand All @@ -46,9 +49,32 @@ public void keyDown(@NonNull KeyEvent keyEvent) {

private void encodeKeyEvent(@NonNull KeyEvent event, @NonNull Map<String, Object> message) {
message.put("flags", event.getFlags());
message.put("codePoint", event.getUnicodeChar());
int codePoint = event.getUnicodeChar();
message.put("plainCodePoint", event.getUnicodeChar(0x0));
message.put("codePoint", codePoint);
message.put("keyCode", event.getKeyCode());
message.put("scanCode", event.getScanCode());
message.put("metaState", event.getMetaState());
if (codePoint == 0) {
return;
}
if ((codePoint & KeyCharacterMap.COMBINING_ACCENT) != 0) {
// If a combining character was entered before, combine this one with that one.
int plainCodePoint = codePoint & KeyCharacterMap.COMBINING_ACCENT_MASK;
if (mCombiningCharacter != 0) {
mCombiningCharacter = KeyCharacterMap.getDeadChar(mCombiningCharacter, plainCodePoint);
} else {
mCombiningCharacter = plainCodePoint;
}
} else {
if (mCombiningCharacter != 0) {
int combinedChar = KeyCharacterMap.getDeadChar(mCombiningCharacter, codePoint);
if (combinedChar > 0) {
codePoint = combinedChar;
}
mCombiningCharacter = 0;
}
message.put("character", Character.toString((char) codePoint));
}
}
}