Keep count of the trailing single quotes for suggestions
Bug: 5665809 Change-Id: I4d9100dbe980861ccb55c78464524be670cac1f7
This commit is contained in:
parent
e2d00ab470
commit
117fc18ed4
3 changed files with 40 additions and 23 deletions
|
@ -1793,6 +1793,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// The whitelist should be case-insensitive, so it's not possible to be consistent with
|
// The whitelist should be case-insensitive, so it's not possible to be consistent with
|
||||||
// a boolean flag. Right now this is handled with a slight hack in
|
// a boolean flag. Right now this is handled with a slight hack in
|
||||||
// WhitelistDictionary#shouldForciblyAutoCorrectFrom.
|
// WhitelistDictionary#shouldForciblyAutoCorrectFrom.
|
||||||
|
final int quotesCount = wordComposer.trailingSingleQuotesCount();
|
||||||
final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
|
final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
|
||||||
mSuggest.getUnigramDictionaries(),
|
mSuggest.getUnigramDictionaries(),
|
||||||
// If the typed string ends with a single quote, for dictionary lookup purposes
|
// If the typed string ends with a single quote, for dictionary lookup purposes
|
||||||
|
@ -1800,8 +1801,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// typed string in the dictionary (to avoid autocorrecting from an existing
|
// typed string in the dictionary (to avoid autocorrecting from an existing
|
||||||
// word, so for consistency this lookup should be made WITHOUT the trailing
|
// word, so for consistency this lookup should be made WITHOUT the trailing
|
||||||
// single quote.
|
// single quote.
|
||||||
wordComposer.isLastCharASingleQuote()
|
quotesCount > 0
|
||||||
? typedWord.subSequence(0, typedWord.length() - 1) : typedWord,
|
? typedWord.subSequence(0, typedWord.length() - quotesCount) : typedWord,
|
||||||
preferCapitalization());
|
preferCapitalization());
|
||||||
if (mCorrectionMode == Suggest.CORRECTION_FULL
|
if (mCorrectionMode == Suggest.CORRECTION_FULL
|
||||||
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
|
||||||
|
|
|
@ -82,8 +82,6 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
public static final String DICT_KEY_USER_BIGRAM = "user_bigram";
|
public static final String DICT_KEY_USER_BIGRAM = "user_bigram";
|
||||||
public static final String DICT_KEY_WHITELIST ="whitelist";
|
public static final String DICT_KEY_WHITELIST ="whitelist";
|
||||||
|
|
||||||
private static String SINGLE_QUOTE_AS_STRING = String.valueOf((char)Keyboard.CODE_SINGLE_QUOTE);
|
|
||||||
|
|
||||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||||
|
|
||||||
private AutoCorrection mAutoCorrection;
|
private AutoCorrection mAutoCorrection;
|
||||||
|
@ -109,7 +107,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
// TODO: Remove these member variables by passing more context to addWord() callback method
|
// TODO: Remove these member variables by passing more context to addWord() callback method
|
||||||
private boolean mIsFirstCharCapitalized;
|
private boolean mIsFirstCharCapitalized;
|
||||||
private boolean mIsAllUpperCase;
|
private boolean mIsAllUpperCase;
|
||||||
private boolean mIsLastCharASingleQuote;
|
private int mTrailingSingleQuotesCount;
|
||||||
|
|
||||||
private int mCorrectionMode = CORRECTION_BASIC;
|
private int mCorrectionMode = CORRECTION_BASIC;
|
||||||
|
|
||||||
|
@ -299,13 +297,14 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
mAutoCorrection.init();
|
mAutoCorrection.init();
|
||||||
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
|
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
|
||||||
mIsAllUpperCase = wordComposer.isAllUpperCase();
|
mIsAllUpperCase = wordComposer.isAllUpperCase();
|
||||||
mIsLastCharASingleQuote = wordComposer.isLastCharASingleQuote();
|
mTrailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
|
||||||
collectGarbage(mSuggestions, mPrefMaxSuggestions);
|
collectGarbage(mSuggestions, mPrefMaxSuggestions);
|
||||||
Arrays.fill(mScores, 0);
|
Arrays.fill(mScores, 0);
|
||||||
|
|
||||||
final String typedWord = wordComposer.getTypedWord();
|
final String typedWord = wordComposer.getTypedWord();
|
||||||
final String consideredWord = mIsLastCharASingleQuote
|
final String consideredWord = mTrailingSingleQuotesCount > 0
|
||||||
? typedWord.substring(0, typedWord.length() - 1) : typedWord;
|
? typedWord.substring(0, typedWord.length() - mTrailingSingleQuotesCount)
|
||||||
|
: typedWord;
|
||||||
if (typedWord != null) {
|
if (typedWord != null) {
|
||||||
// Treating USER_TYPED as UNIGRAM suggestion for logging now.
|
// Treating USER_TYPED as UNIGRAM suggestion for logging now.
|
||||||
LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED,
|
LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED,
|
||||||
|
@ -360,9 +359,11 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
if (key.equals(DICT_KEY_USER_UNIGRAM) || key.equals(DICT_KEY_WHITELIST))
|
||||||
continue;
|
continue;
|
||||||
final Dictionary dictionary = mUnigramDictionaries.get(key);
|
final Dictionary dictionary = mUnigramDictionaries.get(key);
|
||||||
if (mIsLastCharASingleQuote) {
|
if (mTrailingSingleQuotesCount > 0) {
|
||||||
final WordComposer tmpWordComposer = new WordComposer(wordComposer);
|
final WordComposer tmpWordComposer = new WordComposer(wordComposer);
|
||||||
tmpWordComposer.deleteLast();
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
|
tmpWordComposer.deleteLast();
|
||||||
|
}
|
||||||
dictionary.getWords(tmpWordComposer, this, proximityInfo);
|
dictionary.getWords(tmpWordComposer, this, proximityInfo);
|
||||||
} else {
|
} else {
|
||||||
dictionary.getWords(wordComposer, this, proximityInfo);
|
dictionary.getWords(wordComposer, this, proximityInfo);
|
||||||
|
@ -380,8 +381,15 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
whitelistedWord);
|
whitelistedWord);
|
||||||
|
|
||||||
if (whitelistedWord != null) {
|
if (whitelistedWord != null) {
|
||||||
mSuggestions.add(0, mIsLastCharASingleQuote
|
if (mTrailingSingleQuotesCount > 0) {
|
||||||
? whitelistedWord + SINGLE_QUOTE_AS_STRING : whitelistedWord);
|
final StringBuilder sb = new StringBuilder(whitelistedWord);
|
||||||
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
|
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
||||||
|
}
|
||||||
|
mSuggestions.add(0, sb.toString());
|
||||||
|
} else {
|
||||||
|
mSuggestions.add(0, whitelistedWord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typedWord != null) {
|
if (typedWord != null) {
|
||||||
|
@ -500,7 +508,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
} else {
|
} else {
|
||||||
sb.append(word, offset, length);
|
sb.append(word, offset, length);
|
||||||
}
|
}
|
||||||
if (mIsLastCharASingleQuote) {
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
||||||
}
|
}
|
||||||
suggestions.add(pos, sb);
|
suggestions.add(pos, sb);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class WordComposer {
|
||||||
|
|
||||||
private boolean mAutoCapitalized;
|
private boolean mAutoCapitalized;
|
||||||
// Cache this value for performance
|
// Cache this value for performance
|
||||||
private boolean mIsLastCharASingleQuote;
|
private int mTrailingSingleQuotesCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the user chose to capitalize the first char of the word.
|
* Whether the user chose to capitalize the first char of the word.
|
||||||
|
@ -57,7 +57,7 @@ public class WordComposer {
|
||||||
mTypedWord = new StringBuilder(N);
|
mTypedWord = new StringBuilder(N);
|
||||||
mXCoordinates = new int[N];
|
mXCoordinates = new int[N];
|
||||||
mYCoordinates = new int[N];
|
mYCoordinates = new int[N];
|
||||||
mIsLastCharASingleQuote = false;
|
mTrailingSingleQuotesCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WordComposer(WordComposer source) {
|
public WordComposer(WordComposer source) {
|
||||||
|
@ -72,7 +72,7 @@ public class WordComposer {
|
||||||
mCapsCount = source.mCapsCount;
|
mCapsCount = source.mCapsCount;
|
||||||
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
|
||||||
mAutoCapitalized = source.mAutoCapitalized;
|
mAutoCapitalized = source.mAutoCapitalized;
|
||||||
mIsLastCharASingleQuote = source.mIsLastCharASingleQuote;
|
mTrailingSingleQuotesCount = source.mTrailingSingleQuotesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ public class WordComposer {
|
||||||
mTypedWord.setLength(0);
|
mTypedWord.setLength(0);
|
||||||
mCapsCount = 0;
|
mCapsCount = 0;
|
||||||
mIsFirstCharCapitalized = false;
|
mIsFirstCharCapitalized = false;
|
||||||
mIsLastCharASingleQuote = false;
|
mTrailingSingleQuotesCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,7 +133,11 @@ public class WordComposer {
|
||||||
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
mIsFirstCharCapitalized = isFirstCharCapitalized(
|
||||||
newIndex, primaryCode, mIsFirstCharCapitalized);
|
newIndex, primaryCode, mIsFirstCharCapitalized);
|
||||||
if (Character.isUpperCase(primaryCode)) mCapsCount++;
|
if (Character.isUpperCase(primaryCode)) mCapsCount++;
|
||||||
mIsLastCharASingleQuote = Keyboard.CODE_SINGLE_QUOTE == primaryCode;
|
if (Keyboard.CODE_SINGLE_QUOTE == primaryCode) {
|
||||||
|
++mTrailingSingleQuotesCount;
|
||||||
|
} else {
|
||||||
|
mTrailingSingleQuotesCount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,10 +169,14 @@ public class WordComposer {
|
||||||
}
|
}
|
||||||
if (size() == 0) {
|
if (size() == 0) {
|
||||||
mIsFirstCharCapitalized = false;
|
mIsFirstCharCapitalized = false;
|
||||||
mIsLastCharASingleQuote = false;
|
}
|
||||||
|
if (mTrailingSingleQuotesCount > 0) {
|
||||||
|
--mTrailingSingleQuotesCount;
|
||||||
} else {
|
} else {
|
||||||
mIsLastCharASingleQuote =
|
for (int i = mTypedWord.length() - 1; i >= 0; --i) {
|
||||||
Keyboard.CODE_SINGLE_QUOTE == mTypedWord.codePointAt(mTypedWord.length() - 1);
|
if (Keyboard.CODE_SINGLE_QUOTE != mTypedWord.codePointAt(i)) break;
|
||||||
|
++mTrailingSingleQuotesCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +199,8 @@ public class WordComposer {
|
||||||
return mIsFirstCharCapitalized;
|
return mIsFirstCharCapitalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLastCharASingleQuote() {
|
public int trailingSingleQuotesCount() {
|
||||||
return mIsLastCharASingleQuote;
|
return mTrailingSingleQuotesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue