Skip to content

Commit 4ec2d54

Browse files
committed
SDLSurfaceView: add suport for forwarding keystrokes while text
prediction is working not just at the end.
1 parent bda532d commit 4ec2d54

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,44 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
10211021
outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT;
10221022
// ask IME to avoid taking full screen on landscape mode
10231023
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
1024-
return new BaseInputConnection(this, false);
1024+
return new BaseInputConnection(this, false){
1025+
1026+
private int mDelLen = 0;
1027+
1028+
private void deleteLastText(){
1029+
// send back space keys
1030+
for (int i = 0; i < this.mDelLen; i++){
1031+
nativeKey(KeyEvent.KEYCODE_DEL, 1, 23);
1032+
nativeKey(KeyEvent.KEYCODE_DEL, 0, 23);
1033+
}
1034+
}
1035+
1036+
@Override
1037+
public boolean setComposingText(CharSequence text,
1038+
int newCursorPosition){
1039+
//Log.i("Python:", String.format("set Composing Text %s", text));
1040+
this.deleteLastText();
1041+
// send text
1042+
for(int i = 0; i < text.length(); i++){
1043+
// Calls both up/down events to emulate key pressing
1044+
char c = text.charAt(i);
1045+
nativeKey(45, 1, (int) c);
1046+
nativeKey(45, 0, (int) c);
1047+
}
1048+
// store len to be deleted for next time
1049+
this.mDelLen = text.length();
1050+
return super.setComposingText(text, newCursorPosition);
1051+
}
1052+
1053+
@Override
1054+
public boolean commitText(CharSequence text, int newCursorPosition) {
1055+
// some code which takes the input and manipulates it and calls editText.getText().replace() afterwards
1056+
//Log.i("Python:", String.format("Commit Text %s", text));
1057+
this.deleteLastText();
1058+
this.mDelLen = 0;
1059+
return super.commitText(text, newCursorPosition);
1060+
}
1061+
};
10251062
}
10261063

10271064
static void activateInput() {

0 commit comments

Comments
 (0)