Fix ArrayIndexOutOfBoundsException in WordComposer
Bug: 3028277 Change-Id: I1c4d8dca4db8a70f851589d1fbd45a16ea1bfc1bmain
parent
8493e43148
commit
d1a8e3088b
|
@ -25,14 +25,14 @@ public class WordComposer {
|
||||||
/**
|
/**
|
||||||
* The list of unicode values for each keystroke (including surrounding keys)
|
* The list of unicode values for each keystroke (including surrounding keys)
|
||||||
*/
|
*/
|
||||||
private ArrayList<int[]> mCodes;
|
private final ArrayList<int[]> mCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The word chosen from the candidate list, until it is committed.
|
* The word chosen from the candidate list, until it is committed.
|
||||||
*/
|
*/
|
||||||
private String mPreferredWord;
|
private String mPreferredWord;
|
||||||
|
|
||||||
private StringBuilder mTypedWord;
|
private final StringBuilder mTypedWord;
|
||||||
|
|
||||||
private int mCapsCount;
|
private int mCapsCount;
|
||||||
|
|
||||||
|
@ -116,12 +116,15 @@ public class WordComposer {
|
||||||
* Delete the last keystroke as a result of hitting backspace.
|
* Delete the last keystroke as a result of hitting backspace.
|
||||||
*/
|
*/
|
||||||
public void deleteLast() {
|
public void deleteLast() {
|
||||||
mCodes.remove(mCodes.size() - 1);
|
final int codesSize = mCodes.size();
|
||||||
|
if (codesSize > 0) {
|
||||||
|
mCodes.remove(codesSize - 1);
|
||||||
final int lastPos = mTypedWord.length() - 1;
|
final int lastPos = mTypedWord.length() - 1;
|
||||||
char last = mTypedWord.charAt(lastPos);
|
char last = mTypedWord.charAt(lastPos);
|
||||||
mTypedWord.deleteCharAt(lastPos);
|
mTypedWord.deleteCharAt(lastPos);
|
||||||
if (Character.isUpperCase(last)) mCapsCount--;
|
if (Character.isUpperCase(last)) mCapsCount--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the word as it was typed, without any correction applied.
|
* Returns the word as it was typed, without any correction applied.
|
||||||
|
@ -132,15 +135,6 @@ public class WordComposer {
|
||||||
if (wordSize == 0) {
|
if (wordSize == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// StringBuffer sb = new StringBuffer(wordSize);
|
|
||||||
// for (int i = 0; i < wordSize; i++) {
|
|
||||||
// char c = (char) mCodes.get(i)[0];
|
|
||||||
// if (i == 0 && mIsCapitalized) {
|
|
||||||
// c = Character.toUpperCase(c);
|
|
||||||
// }
|
|
||||||
// sb.append(c);
|
|
||||||
// }
|
|
||||||
// return sb;
|
|
||||||
return mTypedWord;
|
return mTypedWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue