aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java39
1 files changed, 30 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a820a40e3..29cf63de4 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -988,13 +988,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
}
+ private static boolean canBeFollowedByPeriod(final int codePoint) {
+ // TODO: Check again whether there really ain't a better way to check this.
+ // TODO: This should probably be language-dependant...
+ return Character.isLetterOrDigit(codePoint)
+ || codePoint == Keyboard.CODE_SINGLE_QUOTE
+ || codePoint == Keyboard.CODE_DOUBLE_QUOTE
+ || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS
+ || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET
+ || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET
+ || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET;
+ }
+
private void maybeDoubleSpace() {
if (mCorrectionMode == Suggest.CORRECTION_NONE) return;
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
- CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
+ final CharSequence lastThree = ic.getTextBeforeCursor(3, 0);
if (lastThree != null && lastThree.length() == 3
- && Character.isLetterOrDigit(lastThree.charAt(0))
+ && canBeFollowedByPeriod(lastThree.charAt(0))
&& lastThree.charAt(1) == Keyboard.CODE_SPACE
&& lastThree.charAt(2) == Keyboard.CODE_SPACE
&& mHandler.isAcceptingDoubleSpaces()) {
@@ -1498,9 +1510,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final WordComposer wordComposer = mWordComposer;
// TODO: May need a better way of retrieving previous word
- CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
- mSettingsValues.mWordSeparators);
- SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
+ final InputConnection ic = getCurrentInputConnection();
+ final CharSequence prevWord;
+ if (null == ic) {
+ prevWord = null;
+ } else {
+ prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
+ }
+ // getSuggestedWordBuilder handles gracefully a null value of prevWord
+ final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord);
boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
@@ -1772,10 +1790,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// We don't want to register as bigrams words separated by a separator.
// For example "I will, and you too" : we don't want the pair ("will" "and") to be
// a bigram.
- CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
- mSettingsValues.mWordSeparators);
- if (!TextUtils.isEmpty(prevWord)) {
- mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString());
+ final InputConnection ic = getCurrentInputConnection();
+ if (null != ic) {
+ final CharSequence prevWord =
+ EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
+ if (!TextUtils.isEmpty(prevWord)) {
+ mUserBigramDictionary.addBigrams(prevWord.toString(), suggestion.toString());
+ }
}
}
}