Skip to content

Commit

Permalink
Fixed bug 2265 - Voice to text feature on Android repeats some text v…
Browse files Browse the repository at this point in the history
…ia SDL_TEXTINPUT

Sylvain

Small patch for this issue. I tested it and it seems to work.

- it can send several backspaces (instead of only 1).
- it calls directly "sendKeyEvent()" instead of "super.sendKeyEvent()".
  otherwise, it would go through the android internals, calling again "onKey()".
  and then the "backspace" would arrive after the next "commitText()".
  • Loading branch information
slouken committed Aug 28, 2017
1 parent 5ca0152 commit 6885bc8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -1683,10 +1683,16 @@ public boolean setComposingText(CharSequence text, int newCursorPosition) {
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
// Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection
if (beforeLength == 1 && afterLength == 0) {
// backspace
return super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& super.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
// and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
if (beforeLength > 0 && afterLength == 0) {
boolean ret = true;
// backspace(s)
while (beforeLength-- > 0) {
boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
ret = ret && ret_key;
}
return ret;
}

return super.deleteSurroundingText(beforeLength, afterLength);
Expand Down

0 comments on commit 6885bc8

Please sign in to comment.