mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-20 06:37:40 +00:00
Merge pull request #10857 from keymanapp/fix/android/subsequence-crash
fix(android/engine): Check selection indexes
This commit is contained in:
commit
cbda2b46c7
1 changed files with 21 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ import com.keyman.engine.KMManager.KeyboardType;
|
|||
import com.keyman.engine.data.Keyboard;
|
||||
import com.keyman.engine.util.CharSequenceUtil;
|
||||
import com.keyman.engine.util.KMLog;
|
||||
import com.keyman.engine.util.KMString;
|
||||
|
||||
public class KMKeyboardJSHandler {
|
||||
private Context context;
|
||||
|
|
@ -284,7 +285,17 @@ public class KMKeyboardJSHandler {
|
|||
|
||||
// Chop dn+numPairs code points from the end of charsBackup
|
||||
// subSequence indices are start(inclusive) to end(exclusive)
|
||||
CharSequence expectedChars = charsBackup.subSequence(0, charsBackup.length() - (dn + numPairs));
|
||||
int start = 0;
|
||||
int end = charsBackup.length() - (dn + numPairs);
|
||||
CharSequence expectedChars;
|
||||
try {
|
||||
expectedChars = charsBackup.subSequence(start, end);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
KMLog.LogException(TAG,
|
||||
KMString.format("Bad subSequence of start %d, end is %d, length %d, dn %d, numPairs %d",
|
||||
start, end, charsBackup.length(), dn, numPairs), e);
|
||||
expectedChars = "";
|
||||
}
|
||||
ic.deleteSurroundingText(dn + numPairs, 0);
|
||||
CharSequence newContext = getCharacterSequence(ic, originalBufferLength - 2*dn);
|
||||
|
||||
|
|
@ -327,7 +338,15 @@ public class KMKeyboardJSHandler {
|
|||
if (Character.isLowSurrogate(sequence.charAt(0))) {
|
||||
// Adjust if the first char is also a split surrogate pair
|
||||
// subSequence indices are start(inclusive) to end(exclusive)
|
||||
sequence = sequence.subSequence(1, sequence.length());
|
||||
int start = 1;
|
||||
int end = sequence.length();
|
||||
try {
|
||||
sequence = sequence.subSequence(start, end);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
KMLog.LogException(TAG,
|
||||
KMString.format("Bad subSequence of start %d, end is %d",
|
||||
start, end), e);
|
||||
}
|
||||
}
|
||||
|
||||
return sequence;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue