fix red spell check for words ending in period on newer android versions, fixes #32

commit d9c7fd89548926eca24d22cbc784278df33eec47
Author: icburns <icburns@uw.edu>
Date:   Thu Aug 18 17:51:50 2022 -0700

    #520 modify CHECKABILITY_CONTAINS_PERIOD logic to for capitalized words in suggestions.

commit 630e03d88f0c3db9749fea228fd10a684c27732d
Author: icburns <icburns@uw.edu>
Date:   Thu Aug 18 17:47:23 2022 -0700

    #520 modify CHECKABILITY_CONTAINS_PERIOD logic to account for period only present in the last index (valid end of sentence).
This commit is contained in:
Helium314 2023-07-25 14:41:11 +02:00
parent 92d03dfa6c
commit a1cf043083

View file

@ -296,16 +296,19 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
// 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[] {
@ -314,8 +317,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
}
return mService.isValidWord(mLocale, text) ?
AndroidSpellCheckerService.getInDictEmptySuggestions() :
AndroidSpellCheckerService.getNotInDictEmptySuggestions(
CHECKABILITY_CONTAINS_PERIOD == checkability /* reportAsTypo */);
AndroidSpellCheckerService.getNotInDictEmptySuggestions(!periodOnlyAtLastIndex);
}
// Handle normal words.