Merge "Fix getNthPreviousWord."
This commit is contained in:
commit
177a86d394
3 changed files with 21 additions and 18 deletions
|
@ -2541,7 +2541,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (currentSettings.mCurrentLanguageHasSpaces) {
|
if (currentSettings.mCurrentLanguageHasSpaces) {
|
||||||
// If we are typing in a language with spaces we can just look up the previous
|
// If we are typing in a language with spaces we can just look up the previous
|
||||||
// word from textview.
|
// word from textview.
|
||||||
return mConnection.getNthPreviousWord(currentSettings.mWordSeparators,
|
return mConnection.getNthPreviousWord(currentSettings,
|
||||||
mWordComposer.isComposingWord() ? 2 : 1);
|
mWordComposer.isComposingWord() ? 2 : 1);
|
||||||
} else {
|
} else {
|
||||||
return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
|
return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
|
||||||
|
@ -2832,7 +2832,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
|
final UserHistoryDictionary userHistoryDictionary = mUserHistoryDictionary;
|
||||||
if (userHistoryDictionary == null) return null;
|
if (userHistoryDictionary == null) return null;
|
||||||
|
|
||||||
final String prevWord = mConnection.getNthPreviousWord(currentSettings.mWordSeparators, 2);
|
final String prevWord = mConnection.getNthPreviousWord(currentSettings, 2);
|
||||||
final String secondWord;
|
final String secondWord;
|
||||||
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
if (mWordComposer.wasAutoCapitalized() && !mWordComposer.isMostlyCaps()) {
|
||||||
secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
secondWord = suggestion.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
|
||||||
|
|
|
@ -538,7 +538,7 @@ public final class RichInputConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public String getNthPreviousWord(final String sentenceSeperators, final int n) {
|
public String getNthPreviousWord(final SettingsValues currentSettingsValues, final int n) {
|
||||||
mIC = mParent.getCurrentInputConnection();
|
mIC = mParent.getCurrentInputConnection();
|
||||||
if (null == mIC) return null;
|
if (null == mIC) return null;
|
||||||
final CharSequence prev = getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
final CharSequence prev = getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
|
||||||
|
@ -557,7 +557,7 @@ public final class RichInputConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getNthPreviousWord(prev, sentenceSeperators, n);
|
return getNthPreviousWord(prev, currentSettingsValues, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSeparator(int code, String sep) {
|
private static boolean isSeparator(int code, String sep) {
|
||||||
|
@ -581,7 +581,7 @@ public final class RichInputConnection {
|
||||||
// (n = 2) "abc |" -> null
|
// (n = 2) "abc |" -> null
|
||||||
// (n = 2) "abc. def|" -> null
|
// (n = 2) "abc. def|" -> null
|
||||||
public static String getNthPreviousWord(final CharSequence prev,
|
public static String getNthPreviousWord(final CharSequence prev,
|
||||||
final String sentenceSeperators, final int n) {
|
final SettingsValues currentSettingsValues, final int n) {
|
||||||
if (prev == null) return null;
|
if (prev == null) return null;
|
||||||
final String[] w = spaceRegex.split(prev);
|
final String[] w = spaceRegex.split(prev);
|
||||||
|
|
||||||
|
@ -593,7 +593,8 @@ public final class RichInputConnection {
|
||||||
|
|
||||||
// If ends in a separator, return null
|
// If ends in a separator, return null
|
||||||
final char lastChar = nthPrevWord.charAt(length - 1);
|
final char lastChar = nthPrevWord.charAt(length - 1);
|
||||||
if (sentenceSeperators.contains(String.valueOf(lastChar))) return null;
|
if (currentSettingsValues.isWordSeparator(lastChar)
|
||||||
|
|| currentSettingsValues.isWordConnector(lastChar)) return null;
|
||||||
|
|
||||||
return nthPrevWord;
|
return nthPrevWord;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
||||||
import com.android.inputmethod.latin.utils.TextRange;
|
import com.android.inputmethod.latin.utils.TextRange;
|
||||||
|
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
|
@ -39,7 +40,8 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
|
||||||
|
|
||||||
// The following is meant to be a reasonable default for
|
// The following is meant to be a reasonable default for
|
||||||
// the "word_separators" resource.
|
// the "word_separators" resource.
|
||||||
private static final String sSeparators = ".,:;!?-";
|
private static final SettingsValues sSettings =
|
||||||
|
SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
@ -137,9 +139,9 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
|
||||||
*/
|
*/
|
||||||
public void testGetPreviousWord() {
|
public void testGetPreviousWord() {
|
||||||
// If one of the following cases breaks, the bigram suggestions won't work.
|
// If one of the following cases breaks, the bigram suggestions won't work.
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSeparators, 2), "abc");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSettings, 2), "abc");
|
||||||
assertNull(RichInputConnection.getNthPreviousWord("abc", sSeparators, 2));
|
assertNull(RichInputConnection.getNthPreviousWord("abc", sSettings, 2));
|
||||||
assertNull(RichInputConnection.getNthPreviousWord("abc. def", sSeparators, 2));
|
assertNull(RichInputConnection.getNthPreviousWord("abc. def", sSettings, 2));
|
||||||
|
|
||||||
// The following tests reflect the current behavior of the function
|
// The following tests reflect the current behavior of the function
|
||||||
// RichInputConnection#getNthPreviousWord.
|
// RichInputConnection#getNthPreviousWord.
|
||||||
|
@ -148,15 +150,15 @@ public class RichInputConnectionAndTextRangeTests extends AndroidTestCase {
|
||||||
// this function if needed - especially since it does not seem very
|
// this function if needed - especially since it does not seem very
|
||||||
// logical. These tests are just there to catch any unintentional
|
// logical. These tests are just there to catch any unintentional
|
||||||
// changes in the behavior of the RichInputConnection#getPreviousWord method.
|
// changes in the behavior of the RichInputConnection#getPreviousWord method.
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSeparators, 2), "abc");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSettings, 2), "abc");
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def.", sSeparators, 2), "abc");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def.", sSettings, 2), "abc");
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def .", sSeparators, 2), "def");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def .", sSettings, 2), "def");
|
||||||
assertNull(RichInputConnection.getNthPreviousWord("abc ", sSeparators, 2));
|
assertNull(RichInputConnection.getNthPreviousWord("abc ", sSettings, 2));
|
||||||
|
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSeparators, 1), "def");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def", sSettings, 1), "def");
|
||||||
assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSeparators, 1), "def");
|
assertEquals(RichInputConnection.getNthPreviousWord("abc def ", sSettings, 1), "def");
|
||||||
assertNull(RichInputConnection.getNthPreviousWord("abc def.", sSeparators, 1));
|
assertNull(RichInputConnection.getNthPreviousWord("abc def.", sSettings, 1));
|
||||||
assertNull(RichInputConnection.getNthPreviousWord("abc def .", sSeparators, 1));
|
assertNull(RichInputConnection.getNthPreviousWord("abc def .", sSettings, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue