diff options
author | 2010-08-13 13:29:49 -0700 | |
---|---|---|
committer | 2010-08-17 09:05:24 -0700 | |
commit | c20c5a8d4c29f52075a157098cf8d7192a45ac36 (patch) | |
tree | 8a15bb122c488ad77b96bd321c039c38e5e16272 /java/src/com/android/inputmethod/latin/LatinIME.java | |
parent | c9a181b1b340012fbc8c32d23a3294364a7ad27b (diff) | |
download | latinime-c20c5a8d4c29f52075a157098cf8d7192a45ac36.tar.gz latinime-c20c5a8d4c29f52075a157098cf8d7192a45ac36.tar.xz latinime-c20c5a8d4c29f52075a157098cf8d7192a45ac36.zip |
Fixes for correction mode - reliably show the corrections when tapping on a word.
Also, continue to show the corrections when user keeps replacing the word repeatedly
with different corrections from the suggestion strip. There were problems with
tapping suggestions quickly or tapping the same suggestion more than once (same length).
Also fixes Bug: 2852891 - Text suggestion appears incorrectly when selecting text that's
not a whole word.
Changed the TextEntryState states to an enum type instead of int. Needed it to show the
states for debugging purposes.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b059b6cfe..b1bb84d27 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -752,10 +752,10 @@ public class LatinIME extends InputMethodService mVoiceInputHighlighted = false; } else if (!mPredicting && !mJustAccepted) { switch (TextEntryState.getState()) { - case TextEntryState.STATE_ACCEPTED_DEFAULT: + case ACCEPTED_DEFAULT: TextEntryState.reset(); // fall through - case TextEntryState.STATE_SPACE_AFTER_PICKED: + case SPACE_AFTER_PICKED: mJustAddedAutoSpace = false; // The user moved the cursor. break; } @@ -768,10 +768,10 @@ public class LatinIME extends InputMethodService mLastSelectionEnd = newSelEnd; - // TODO: Uncomment this block when we enable re-editing feature - // If a word is selected + // Check if we should go in or out of correction mode. if (isPredictionOn() && mJustRevertedSeparator == null - && (candidatesStart == candidatesEnd || newSelStart != oldSelStart) + && (candidatesStart == candidatesEnd || newSelStart != oldSelStart + || TextEntryState.isCorrecting()) && (newSelStart < newSelEnd - 1 || (!mPredicting)) && !mVoiceInputHighlighted) { if (isCursorTouchingWord() || mLastSelectionStart < mLastSelectionEnd) { @@ -1207,7 +1207,7 @@ public class LatinIME extends InputMethodService } postUpdateShiftKeyState(); TextEntryState.backspace(); - if (TextEntryState.getState() == TextEntryState.STATE_UNDO_COMMIT) { + if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) { revertLastWord(deleteChar); ic.endBatchEdit(); return; @@ -1358,13 +1358,13 @@ public class LatinIME extends InputMethodService // Handle the case of ". ." -> " .." with auto-space if necessary // before changing the TextEntryState. - if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED + if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED && primaryCode == KEYCODE_PERIOD) { reswapPeriodAndSpace(); } TextEntryState.typedCharacter((char) primaryCode, true); - if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED + if (TextEntryState.getState() == TextEntryState.State.PUNCTUATION_AFTER_ACCEPTED && primaryCode != KEYCODE_ENTER) { swapPunctuationAndSpace(); } else if (isPredictionOn() && primaryCode == KEYCODE_SPACE) { @@ -1790,8 +1790,16 @@ public class LatinIME extends InputMethodService mJustAddedAutoSpace = true; } - // Fool the state watcher so that a subsequent backspace will not do a revert - TextEntryState.typedCharacter((char) KEYCODE_SPACE, true); + // Fool the state watcher so that a subsequent backspace will not do a revert, unless + // we just did a correction, in which case we need to stay in + // TextEntryState.State.PICKED_SUGGESTION state. + if (!correcting) { + TextEntryState.typedCharacter((char) KEYCODE_SPACE, true); + setNextSuggestions(); + } else { + // In case the cursor position doesn't change, make sure we show the suggestions again. + postUpdateOldSuggestions(); + } if (index == 0 && mCorrectionMode > 0 && !mSuggest.isValidWord(suggestion) && !mSuggest.isValidWord(suggestion.toString().toLowerCase())) { mCandidateView.showAddToDictionaryHint(suggestion); @@ -1820,7 +1828,6 @@ public class LatinIME extends InputMethodService mWordToSuggestions.put(suggestion.toString(), suggestions); } } - // TODO: implement rememberReplacedWord for typed words } /** @@ -1860,7 +1867,10 @@ public class LatinIME extends InputMethodService mPredicting = false; mCommittedLength = suggestion.length(); ((LatinKeyboard) inputView.getKeyboard()).setPreferredLetters(null); - setNextSuggestions(); + // If we just corrected a word, then don't show punctuations + if (!correcting) { + setNextSuggestions(); + } updateShiftKeyState(getCurrentInputEditorInfo()); } @@ -1880,13 +1890,16 @@ public class LatinIME extends InputMethodService EditingUtil.Range range = new EditingUtil.Range(); CharSequence touching = EditingUtil.getWordAtCursor(getCurrentInputConnection(), mWordSeparators, range); - if (touching != null && touching.length() > 1) { + // If it's a selection, check if it's an entire word and no more, no less. + boolean fullword = EditingUtil.isFullWordOrInside(range, mLastSelectionStart, + mLastSelectionEnd); + if (fullword && touching != null && touching.length() > 1) { + // Strip out any trailing word separator if (mWordSeparators.indexOf(touching.charAt(touching.length() - 1)) > 0) { touching = touching.toString().substring(0, touching.length() - 1); } // Search for result in spoken word alternatives - // TODO: possibly combine the spoken suggestions with the typed suggestions. String selectedWord = touching.toString().trim(); if (!mWordToSuggestions.containsKey(selectedWord)){ selectedWord = selectedWord.toLowerCase(); @@ -1911,7 +1924,8 @@ public class LatinIME extends InputMethodService ic.endBatchEdit(); return; } - // If we didn't find a match, search for result in word history + + // If we didn't find a match, search for result in typed word history WordComposer foundWord = null; WordAlternatives alternatives = null; for (WordAlternatives entry : mWordHistory) { |