Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #520 Red underline upon sentence completion #679

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,19 @@ protected SuggestionsInfo onGetSuggestionsInternal(
// Handle special patterns like email, URI, telephone number.
final int checkability = getCheckabilityInScript(text, mScript);
if (CHECKABILITY_CHECKABLE != checkability) {
// CHECKABILITY_CONTAINS_PERIOD Typo should not be reported when text is a valid word followed by a single period (end of sentence).
boolean periodOnlyAtLastIndex = text.indexOf(Constants.CODE_PERIOD) == (text.length() - 1);
if (CHECKABILITY_CONTAINS_PERIOD == checkability) {
final String[] splitText = text.split(Constants.REGEXP_PERIOD);
boolean allWordsAreValid = true;
// Validate all words on both sides of periods, skip empty tokens due to periods at first/last index
for (final String word : splitText) {
if (!mService.isValidWord(mLocale, word)) {
if (!word.isEmpty() && !mService.isValidWord(mLocale, word) && !mService.isValidWord(mLocale, word.toLowerCase(mLocale))) {
allWordsAreValid = false;
break;
}
}
if (allWordsAreValid) {
if (allWordsAreValid && !periodOnlyAtLastIndex) {
return new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO
| SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS,
new String[] {
Expand All @@ -314,8 +317,7 @@ protected SuggestionsInfo onGetSuggestionsInternal(
}
return mService.isValidWord(mLocale, text) ?
AndroidSpellCheckerService.getInDictEmptySuggestions() :
AndroidSpellCheckerService.getNotInDictEmptySuggestions(
CHECKABILITY_CONTAINS_PERIOD == checkability /* reportAsTypo */);
AndroidSpellCheckerService.getNotInDictEmptySuggestions(!periodOnlyAtLastIndex);
}

// Handle normal words.
Expand Down