diff options
author | 2012-02-03 12:22:02 +0900 | |
---|---|---|
committer | 2012-02-03 13:03:54 +0900 | |
commit | 825e2bbd910cce3055a4ca808d3744bc0b2cedda (patch) | |
tree | 50164e8ab87f24e8e53508bda28f0fe4dbc72b68 | |
parent | 71915a372209616850e053bc5ac82eab26c170ba (diff) | |
download | latinime-825e2bbd910cce3055a4ca808d3744bc0b2cedda.tar.gz latinime-825e2bbd910cce3055a4ca808d3744bc0b2cedda.tar.xz latinime-825e2bbd910cce3055a4ca808d3744bc0b2cedda.zip |
Fix a bug when deleting the last char
And unit test
Change-Id: Ic4fc3626f8b86e10156d770d41cd6deab5d31f39
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 6 | ||||
-rw-r--r-- | tests/src/com/android/inputmethod/latin/InputLogicTests.java | 9 |
2 files changed, 13 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index fa1b5ef6c..dd24432f7 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -212,6 +212,7 @@ public class WordComposer { final int lastPos = size - 1; char lastChar = mTypedWord.charAt(lastPos); mCodes.remove(lastPos); + // TODO: This crashes and catches fire if the code point doesn't fit a char mTypedWord.deleteCharAt(lastPos); if (Character.isUpperCase(lastChar)) mCapsCount--; } @@ -221,8 +222,9 @@ public class WordComposer { if (mTrailingSingleQuotesCount > 0) { --mTrailingSingleQuotesCount; } else { - for (int i = mTypedWord.offsetByCodePoints(mTypedWord.length(), -1); - i >= 0; i = mTypedWord.offsetByCodePoints(i, -1)) { + int i = mTypedWord.length(); + while (i > 0) { + i = mTypedWord.offsetByCodePoints(i, -1); if (Keyboard.CODE_SINGLE_QUOTE != mTypedWord.codePointAt(i)) break; ++mTrailingSingleQuotesCount; } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index af647b8ce..ee3a97fab 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -291,4 +291,13 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> { assertEquals("manual pick then space then type", WORD1_TO_TYPE + WORD2_TO_TYPE, mTextView.getText().toString()); } + + public void testDeleteWholeComposingWord() { + final String WORD_TO_TYPE = "this"; + type(WORD_TO_TYPE); + for (int i = 0; i < WORD_TO_TYPE.length(); ++i) { + type(Keyboard.CODE_DELETE); + } + assertEquals("delete whole composing word", "", mTextView.getText().toString()); + } } |