am 9b78241d
: Merge "Improve trailing quotes processing"
* commit '9b78241dff6b785408ae19512f6875e63771b349': Improve trailing quotes processing
This commit is contained in:
commit
ef518bfd1c
3 changed files with 47 additions and 2 deletions
|
@ -460,7 +460,7 @@ public final class Suggest {
|
|||
private static final SuggestedWordInfoComparator sSuggestedWordInfoComparator =
|
||||
new SuggestedWordInfoComparator();
|
||||
|
||||
private static SuggestedWordInfo getTransformedSuggestedWordInfo(
|
||||
/* package for test */ static SuggestedWordInfo getTransformedSuggestedWordInfo(
|
||||
final SuggestedWordInfo wordInfo, final Locale locale, final boolean isAllUpperCase,
|
||||
final boolean isFirstCharCapitalized, final int trailingSingleQuotesCount) {
|
||||
final StringBuilder sb = new StringBuilder(wordInfo.mWord.length());
|
||||
|
@ -471,7 +471,12 @@ public final class Suggest {
|
|||
} else {
|
||||
sb.append(wordInfo.mWord);
|
||||
}
|
||||
for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||
// Appending quotes is here to help people quote words. However, it's not helpful
|
||||
// when they type words with quotes toward the end like "it's" or "didn't", where
|
||||
// it's more likely the user missed the last character (or didn't type it yet).
|
||||
final int quotesToAppend = trailingSingleQuotesCount
|
||||
- (-1 == wordInfo.mWord.indexOf(Constants.CODE_SINGLE_QUOTE) ? 0 : 1);
|
||||
for (int i = quotesToAppend - 1; i >= 0; --i) {
|
||||
sb.appendCodePoint(Constants.CODE_SINGLE_QUOTE);
|
||||
}
|
||||
return new SuggestedWordInfo(sb.toString(), wordInfo.mScore, wordInfo.mKind,
|
||||
|
|
|
@ -134,6 +134,13 @@ public class InputLogicTests extends InputTestsBase {
|
|||
assertEquals("simple auto-correct", EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
|
||||
public void testAutoCorrectWithQuote() {
|
||||
final String STRING_TO_TYPE = "didn' ";
|
||||
final String EXPECTED_RESULT = "didn't ";
|
||||
type(STRING_TO_TYPE);
|
||||
assertEquals("auto-correct with quote", EXPECTED_RESULT, mEditText.getText().toString());
|
||||
}
|
||||
|
||||
public void testAutoCorrectWithPeriod() {
|
||||
final String STRING_TO_TYPE = "tgis.";
|
||||
final String EXPECTED_RESULT = "this.";
|
||||
|
|
|
@ -64,4 +64,37 @@ public class SuggestedWordsTests extends AndroidTestCase {
|
|||
assertEquals("0", wordsWithoutTyped.getWord(0));
|
||||
assertEquals(SuggestedWordInfo.KIND_CORRECTION, wordsWithoutTyped.getInfo(0).mKind);
|
||||
}
|
||||
|
||||
// Helper for testGetTransformedWordInfo
|
||||
private SuggestedWordInfo createWordInfo(final String s) {
|
||||
// Use 100 as the frequency because the numerical value does not matter as
|
||||
// long as it's > 1 and < INT_MAX.
|
||||
return new SuggestedWordInfo(s, 100,
|
||||
SuggestedWordInfo.KIND_TYPED, null /* sourceDict */,
|
||||
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
|
||||
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
|
||||
}
|
||||
|
||||
// Helper for testGetTransformedWordInfo
|
||||
private SuggestedWordInfo transformWordInfo(final String info,
|
||||
final int trailingSingleQuotesCount) {
|
||||
return Suggest.getTransformedSuggestedWordInfo(createWordInfo(info),
|
||||
Locale.ENGLISH, false /* isAllUpperCase */, false /* isFirstCharCapitalized */,
|
||||
trailingSingleQuotesCount);
|
||||
}
|
||||
|
||||
public void testGetTransformedSuggestedWordInfo() {
|
||||
SuggestedWordInfo result = transformWordInfo("word", 0);
|
||||
assertEquals(result.mWord, "word");
|
||||
result = transformWordInfo("word", 1);
|
||||
assertEquals(result.mWord, "word'");
|
||||
result = transformWordInfo("word", 3);
|
||||
assertEquals(result.mWord, "word'''");
|
||||
result = transformWordInfo("didn't", 0);
|
||||
assertEquals(result.mWord, "didn't");
|
||||
result = transformWordInfo("didn't", 1);
|
||||
assertEquals(result.mWord, "didn't");
|
||||
result = transformWordInfo("didn't", 3);
|
||||
assertEquals(result.mWord, "didn't''");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue