aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-05-08 18:44:50 +0900
committerJean Chalard <jchalard@google.com>2013-05-08 18:47:10 +0900
commit9f9cc032773a528b4eb6e036db0c37ff45385cce (patch)
tree403073271db2206f6dd72bd8d08755bdda9ef147 /java/src
parentfaa94a2d0abfc8e0f03799dd5f0f2125e44b0bfd (diff)
downloadlatinime-9f9cc032773a528b4eb6e036db0c37ff45385cce.tar.gz
latinime-9f9cc032773a528b4eb6e036db0c37ff45385cce.tar.xz
latinime-9f9cc032773a528b4eb6e036db0c37ff45385cce.zip
Optimizations and safeguards.
- Don't call finishComposingText when useless. - Add safeguards against calling setComposingRegion when the data returned by the editor is inconsistent. - Cancel pending recorrection messages when new messages arrive. Bug: 8842941 Bug: 8845001 Change-Id: I939701033cf5c2bbd85871ecf83e329021ddeb91
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java12
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java5
2 files changed, 13 insertions, 4 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 84c752934..fdd470cf1 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -250,6 +250,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
public void postResumeSuggestions() {
+ removeMessages(MSG_RESUME_SUGGESTIONS);
sendMessageDelayed(obtainMessage(MSG_RESUME_SUGGESTIONS), mDelayUpdateSuggestions);
}
@@ -759,7 +760,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
mSuggestedWords = SuggestedWords.EMPTY;
- mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
+ mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart,
+ false /* shouldFinishComposition */);
if (isDifferentTextField) {
mainKeyboardView.closing();
@@ -1148,13 +1150,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// This will reset the whole input state to the starting state. It will clear
// the composing word, reset the last composed word, tell the inputconnection about it.
private void resetEntireInputState(final int newCursorPosition) {
+ final boolean shouldFinishComposition = mWordComposer.isComposingWord();
resetComposingState(true /* alsoResetLastComposedWord */);
if (mSettings.getCurrent().mBigramPredictionEnabled) {
clearSuggestionStrip();
} else {
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
}
- mConnection.resetCachesUponCursorMove(newCursorPosition);
+ mConnection.resetCachesUponCursorMove(newCursorPosition, shouldFinishComposition);
}
private void resetComposingState(final boolean alsoResetLastComposedWord) {
@@ -2436,10 +2439,15 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void restartSuggestionsOnWordTouchedByCursor() {
// If the cursor is not touching a word, or if there is a selection, return right away.
if (mLastSelectionStart != mLastSelectionEnd) return;
+ // If we don't know the cursor location, return.
+ if (mLastSelectionStart < 0) return;
if (!mConnection.isCursorTouchingWord(mSettings.getCurrent())) return;
final Range range = mConnection.getWordRangeAtCursor(mSettings.getWordSeparators(),
0 /* additionalPrecedingWordsCount */);
if (null == range) return; // Happens if we don't have an input connection at all
+ // If for some strange reason (editor bug or so) we measure the text before the cursor as
+ // longer than what the entire text is supposed to be, the safe thing to do is bail out.
+ if (range.mCharsBefore > mLastSelectionStart) return;
final ArrayList<SuggestedWordInfo> suggestions = CollectionUtils.newArrayList();
final String typedWord = range.mWord.toString();
if (range.mWord instanceof SpannableString) {
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 8ed7ab264..980215de6 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -135,13 +135,14 @@ public final class RichInputConnection {
if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
}
- public void resetCachesUponCursorMove(final int newCursorPosition) {
+ public void resetCachesUponCursorMove(final int newCursorPosition,
+ final boolean shouldFinishComposition) {
mCurrentCursorPosition = newCursorPosition;
mComposingText.setLength(0);
mCommittedTextBeforeComposingText.setLength(0);
final CharSequence textBeforeCursor = getTextBeforeCursor(DEFAULT_TEXT_CACHE_SIZE, 0);
if (null != textBeforeCursor) mCommittedTextBeforeComposingText.append(textBeforeCursor);
- if (null != mIC) {
+ if (null != mIC && shouldFinishComposition) {
mIC.finishComposingText();
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.richInputConnection_finishComposingText();