aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java10
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java9
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java7
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java34
4 files changed, 51 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 51dc85295..31a892e19 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -224,14 +224,10 @@ final public class BinaryDictionaryGetter {
}
}
- // ## HACK ## we prevent usage of a dictionary before version 18 for English only. The reason
- // for this is, since those do not include whitelist entries, the new code with an old version
- // of the dictionary would lose whitelist functionality.
+ // ## HACK ## we prevent usage of a dictionary before version 18. The reason for this is, since
+ // those do not include whitelist entries, the new code with an old version of the dictionary
+ // would lose whitelist functionality.
private static boolean hackCanUseDictionaryFile(final Locale locale, final File f) {
- // Only for English - other languages didn't have a whitelist, hence this
- // ad-hoc ## HACK ##
- if (!Locale.ENGLISH.getLanguage().equals(locale.getLanguage())) return true;
-
FileInputStream inStream = null;
try {
// Read the version of the file
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 9cdb86c2d..a19363d54 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -92,7 +92,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Controls access to the local binary dictionary for this instance. */
private final DictionaryController mLocalDictionaryController = new DictionaryController();
- private static final int BINARY_DICT_VERSION = 1;
+ // TODO: Regenerate version 3 binary dictionary.
+ private static final int BINARY_DICT_VERSION = 2;
private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
new FormatSpec.FormatOptions(BINARY_DICT_VERSION);
@@ -415,6 +416,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// shared dictionary.
loadBinaryDictionary();
}
+ if (mBinaryDictionary != null && !mBinaryDictionary.isValidDictionary()) {
+ // Binary dictionary is not valid. Regenerate the dictionary file.
+ mSharedDictionaryController.mLastUpdateTime = time;
+ generateBinaryDictionary();
+ loadBinaryDictionary();
+ }
mLocalDictionaryController.mLastUpdateTime = time;
} finally {
mSharedDictionaryController.unlock();
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index da5881d00..243928f8b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -961,7 +961,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: is it still necessary to test for composingSpan related stuff?
final boolean selectionChangedOrSafeToReset = selectionChanged
|| (!mWordComposer.isComposingWord()) || noComposingSpan;
- if (selectionChangedOrSafeToReset) {
+ final boolean hasOrHadSelection = (oldSelStart != oldSelEnd
+ || newSelStart != newSelEnd);
+ final int moveAmount = newSelStart - oldSelStart;
+ if (selectionChangedOrSafeToReset && (hasOrHadSelection
+ || !mWordComposer.moveCursorByAndReturnIfInsideComposingWord(moveAmount))) {
// If we are composing a word and moving the cursor, we would want to set a
// suggestion span for recorrection to work correctly. Unfortunately, that
// would involve the keyboard committing some new text, which would move the
@@ -2535,6 +2539,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
mWordComposer.setComposingWord(typedWord, mKeyboardSwitcher.getKeyboard());
+ // TODO: this is in chars but the callee expects code points!
mWordComposer.setCursorPositionWithinWord(numberOfCharsInWordBeforeCursor);
mConnection.setComposingRegion(
mLastSelectionStart - numberOfCharsInWordBeforeCursor,
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index e078f03f4..2babe8b0c 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -192,6 +192,40 @@ public final class WordComposer {
return mCursorPositionWithinWord != mCodePointSize;
}
+ /**
+ * When the cursor is moved by the user, we need to update its position.
+ * If it falls inside the currently composing word, we don't reset the composition, and
+ * only update the cursor position.
+ *
+ * @param expectedMoveAmount How many java chars to move the cursor. Negative values move
+ * the cursor backward, positive values move the cursor forward.
+ * @return true if the cursor is still inside the composing word, false otherwise.
+ */
+ public boolean moveCursorByAndReturnIfInsideComposingWord(final int expectedMoveAmount) {
+ int actualMoveAmountWithinWord = 0;
+ int cursorPos = mCursorPositionWithinWord;
+ if (expectedMoveAmount >= 0) {
+ // Moving the cursor forward for the expected amount or until the end of the word has
+ // been reached, whichever comes first.
+ while (actualMoveAmountWithinWord < expectedMoveAmount && cursorPos < mCodePointSize) {
+ actualMoveAmountWithinWord += Character.charCount(mPrimaryKeyCodes[cursorPos]);
+ ++cursorPos;
+ }
+ } else {
+ // Moving the cursor backward for the expected amount or until the start of the word
+ // has been reached, whichever comes first.
+ while (actualMoveAmountWithinWord > expectedMoveAmount && cursorPos > 0) {
+ --cursorPos;
+ actualMoveAmountWithinWord -= Character.charCount(mPrimaryKeyCodes[cursorPos]);
+ }
+ }
+ // If the actual and expected amounts differ, we crossed the start or the end of the word
+ // so the result would not be inside the composing word.
+ if (actualMoveAmountWithinWord != expectedMoveAmount) return false;
+ mCursorPositionWithinWord = cursorPos;
+ return true;
+ }
+
public void setBatchInputPointers(final InputPointers batchPointers) {
mInputPointers.set(batchPointers);
mIsBatchMode = true;