aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-02-21 23:48:37 -0800
committerJean Chalard <jchalard@google.com>2012-02-21 23:56:36 -0800
commit193d23f40e1556074f323b7bd9695759f4798efe (patch)
treeaa99e3dc31b091511c17c0553f4effdb53fd438e /java/src
parent66bb563535dbe3672f99f75bd71763a551444867 (diff)
downloadlatinime-193d23f40e1556074f323b7bd9695759f4798efe.tar.gz
latinime-193d23f40e1556074f323b7bd9695759f4798efe.tar.xz
latinime-193d23f40e1556074f323b7bd9695759f4798efe.zip
Use the stored separator instead of reading it back (A3)
Now that we have stored our committing separator, we can use it directly instead of reading it back from the text view paying the IPC cost. This prepares for feature request #5968922. Change-Id: Ifeaa2d659cf12b91c89d28e6ff7d07a669258184
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LastComposedWord.java8
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java28
2 files changed, 27 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java
index f0b91b104..d32b22d4f 100644
--- a/java/src/com/android/inputmethod/latin/LastComposedWord.java
+++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java
@@ -76,4 +76,12 @@ public class LastComposedWord {
return mActive && !TextUtils.isEmpty(mCommittedWord)
&& !TextUtils.equals(mTypedWord, mCommittedWord);
}
+
+ public boolean didCommitTypedWord() {
+ return TextUtils.equals(mTypedWord, mCommittedWord);
+ }
+
+ public static int getSeparatorLength(final int separatorCode) {
+ return NOT_A_SEPARATOR == separatorCode ? 0 : 1;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b7c8b70e1..beaccffb3 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -2206,14 +2206,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final String originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
final int cancelLength = committedWord.length();
- final CharSequence separator = ic.getTextBeforeCursor(1, 0);
+ final int separatorLength = mLastComposedWord.getSeparatorLength(
+ mLastComposedWord.mSeparatorCode);
+ // TODO: should we check our saved separator against the actual contents of the text view?
if (DEBUG) {
if (mWordComposer.isComposingWord()) {
throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
}
final String wordBeforeCursor =
- ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
- .toString();
+ ic.getTextBeforeCursor(cancelLength + separatorLength, 0)
+ .subSequence(0, cancelLength).toString();
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
throw new RuntimeException("cancelAutoCorrect check failed: we thought we were "
+ "reverting \"" + committedWord
@@ -2225,13 +2227,21 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
+ "\" but we found this very string before the cursor");
}
}
- ic.deleteSurroundingText(cancelLength + 1, 0);
- ic.commitText(originallyTypedWord, 1);
- // Re-insert the separator
- ic.commitText(separator, 1);
+ ic.deleteSurroundingText(cancelLength + separatorLength, 0);
+ if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) {
+ // This is the case when we cancel a manual pick.
+ // TODO: implement this
+ // We should restart suggestion on the word right away.
+ } else {
+ ic.commitText(originallyTypedWord, 1);
+ // Re-insert the separator
+ sendKeyCodePoint(mLastComposedWord.mSeparatorCode);
+ Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, WordComposer.NOT_A_COORDINATE,
+ WordComposer.NOT_A_COORDINATE);
+ // Don't restart suggestion yet. We'll restart if the user deletes the
+ // separator.
+ }
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
- Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
- WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
}