diff options
author | Artyom Palvelev <artyompp@google.com> | 2024-03-20 17:52:21 +0000 |
---|---|---|
committer | Artyom Palvelev <artyompp@google.com> | 2024-03-20 17:52:21 +0000 |
commit | 5dec41615db92250a0daf80a95d32b83ba8516fb (patch) | |
tree | 27ee0b2901d7ef2c6d9cac9766209a88b59d4571 | |
parent | 76243d802b6f86b9363aac48464f09af900c0d9b (diff) | |
download | gamesdk-5dec41615db92250a0daf80a95d32b83ba8516fb.tar.gz |
fix selection when typing with hardware keyboard
Selection interval haven't been updated correctly in cases when
characters are inserted not at the end of the string.
Test: build and run AGDKTunnel and test that typing works
Fix: 329405226
Change-Id: Idafaae29d87c841d0909282f53f9bd8404114154
-rw-r--r-- | game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java index 469897bf..07aa9f3c 100644 --- a/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java +++ b/game-text-input/src/main/java/com/google/androidgamesdk/gametextinput/InputConnection.java @@ -517,8 +517,9 @@ public class InputConnection int code = event.getKeyCode(); if (!dontInsertChars.get(code)) { + String charsToInsert = Character.toString((char) event.getUnicodeChar()); this.mEditable.insert( - selection.first, (CharSequence) Character.toString((char) event.getUnicodeChar())); + selection.first, (CharSequence) charsToInsert); int length = this.mEditable.length(); // Same logic as in setComposingText(): we must update composing region, @@ -531,11 +532,11 @@ public class InputConnection } } - // IMM seems to cache set content of Editable, so we update it with restartInput + // IMM seems to cache the content of Editable, so we update it with restartInput // Also it caches selection and composing region, so let's notify it about updates. composingRegion.second = composingRegion.first + length; this.setComposingRegion(composingRegion.first, composingRegion.second); - int new_cursor = composingRegion.second; + int new_cursor = selection.first + charsToInsert.length(); setSelectionInternal(new_cursor, new_cursor); this.informIMM(); this.restartInput(); |