diff options
author | 2012-02-03 16:05:48 +0900 | |
---|---|---|
committer | 2012-02-08 15:45:51 +0900 | |
commit | 9159b9953d857de83ae2f90a121fcd259f5ee01d (patch) | |
tree | 1ee3ab95e23431a8306a2e3d7a37e4ce19be067b /java/src | |
parent | 8174373a0ed11aaaf6d5cdfc9065e6b8641b19a6 (diff) | |
download | latinime-9159b9953d857de83ae2f90a121fcd259f5ee01d.tar.gz latinime-9159b9953d857de83ae2f90a121fcd259f5ee01d.tar.xz latinime-9159b9953d857de83ae2f90a121fcd259f5ee01d.zip |
Fix the auto-composer to support supplementary chars
Change-Id: I61ff218ae2ca4eb443a370e581b677755258670a
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index f418968b5..a1a329a8d 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -90,11 +90,11 @@ public class WordComposer { * @return the number of keystrokes */ public final int size() { - return mTypedWord.length(); + return mCodes.size(); } public final boolean isComposingWord() { - return size() > 0; + return mCodes.size() > 0; } /** @@ -125,8 +125,8 @@ public class WordComposer { * @param codes the array of unicode values */ public void add(int primaryCode, int[] codes, int x, int y) { - final int newIndex = size(); - mTypedWord.append((char) primaryCode); + final int newIndex = mCodes.size(); + mTypedWord.appendCodePoint(primaryCode); correctPrimaryJuxtapos(primaryCode, codes); mCodes.add(codes); if (newIndex < BinaryDictionary.MAX_WORD_LENGTH) { @@ -171,8 +171,8 @@ public class WordComposer { final KeyDetector keyDetector) { reset(); final int length = word.length(); - for (int i = 0; i < length; ++i) { - int codePoint = word.charAt(i); + for (int i = 0; i < length; i = Character.offsetByCodePoints(word, i, 1)) { + int codePoint = Character.codePointAt(word, i); addKeyInfo(codePoint, keyboard, keyDetector); } } @@ -207,16 +207,25 @@ public class WordComposer { * Delete the last keystroke as a result of hitting backspace. */ public void deleteLast() { - final int size = size(); + final int size = mCodes.size(); if (size > 0) { - 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); + mCodes.remove(size - 1); + // Note: mTypedWord.length() and mCodes.length differ when there are surrogate pairs + final int stringBuilderLength = mTypedWord.length(); + if (stringBuilderLength < size) { + throw new RuntimeException( + "In WordComposer: mCodes and mTypedWords have non-matching lengths"); + } + final int lastChar = mTypedWord.codePointBefore(stringBuilderLength); + if (Character.isSupplementaryCodePoint(lastChar)) { + mTypedWord.delete(stringBuilderLength - 2, stringBuilderLength); + } else { + mTypedWord.deleteCharAt(stringBuilderLength - 1); + } if (Character.isUpperCase(lastChar)) mCapsCount--; } - if (size() == 0) { + // We may have deleted the last one. + if (0 == mCodes.size()) { mIsFirstCharCapitalized = false; } if (mTrailingSingleQuotesCount > 0) { |