Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65b6f47a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix a bug in SpellCheckSpan update logic." into sc-dev am: 7568c8cd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14609923

Change-Id: I46607b0cecaaa79f2d343775c1d6186071ef9312
parents a1230e2d 7568c8cd
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -375,6 +375,13 @@ public class SpellChecker implements SpellCheckerSessionListener {
        final int sequenceNumber = suggestionsInfo.getSequence();
        for (int k = 0; k < mLength; ++k) {
            if (sequenceNumber == mIds[k]) {
                final SpellCheckSpan spellCheckSpan = mSpellCheckSpans[k];
                final int spellCheckSpanStart = editable.getSpanStart(spellCheckSpan);
                if (spellCheckSpanStart < 0) {
                    // Skips the suggestion if the matched span has been removed.
                    return null;
                }

                final int attributes = suggestionsInfo.getSuggestionsAttributes();
                final boolean isInDictionary =
                        ((attributes & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) > 0);
@@ -383,7 +390,11 @@ public class SpellChecker implements SpellCheckerSessionListener {
                final boolean looksLikeGrammarError =
                        ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_GRAMMAR_ERROR) > 0);

                final SpellCheckSpan spellCheckSpan = mSpellCheckSpans[k];
                // Validates the suggestions range in case the SpellCheckSpan is out-of-date but not
                // removed as expected.
                if (spellCheckSpanStart + offset + length > editable.length()) {
                    return spellCheckSpan;
                }
                //TODO: we need to change that rule for results from a sentence-level spell
                // checker that will probably be in dictionary.
                if (!isInDictionary && (looksLikeTypo || looksLikeGrammarError)) {
@@ -393,7 +404,6 @@ public class SpellChecker implements SpellCheckerSessionListener {
                    // Valid word -- isInDictionary || !looksLikeTypo
                    // Allow the spell checker to remove existing misspelled span by
                    // overwriting the span over the same place
                    final int spellCheckSpanStart = editable.getSpanStart(spellCheckSpan);
                    final int spellCheckSpanEnd = editable.getSpanEnd(spellCheckSpan);
                    final int start;
                    final int end;
@@ -461,7 +471,6 @@ public class SpellChecker implements SpellCheckerSessionListener {
    @Override
    public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
        final Editable editable = (Editable) mTextView.getText();
        final int sentenceLength = editable.length();
        for (int i = 0; i < results.length; ++i) {
            final SentenceSuggestionsInfo ssi = results[i];
            if (ssi == null) {
@@ -475,9 +484,6 @@ public class SpellChecker implements SpellCheckerSessionListener {
                }
                final int offset = ssi.getOffsetAt(j);
                final int length = ssi.getLengthAt(j);
                if (offset < 0 || offset + length > sentenceLength) {
                    continue;
                }
                final SpellCheckSpan scs = onGetSuggestionsInternal(
                        suggestionsInfo, offset, length);
                if (spellCheckSpan == null && scs != null) {
+9 −6
Original line number Diff line number Diff line
@@ -10750,12 +10750,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        Editable text = (Editable) mText;
        T[] spans = text.getSpans(start, end, type);
        final int length = spans.length;
        for (int i = 0; i < length; i++) {
            final int spanStart = text.getSpanStart(spans[i]);
            final int spanEnd = text.getSpanEnd(spans[i]);
            if (spanEnd == start || spanStart == end) break;
            text.removeSpan(spans[i]);
        ArrayList<T> spansToRemove = new ArrayList<>();
        for (T span : spans) {
            final int spanStart = text.getSpanStart(span);
            final int spanEnd = text.getSpanEnd(span);
            if (spanEnd == start || spanStart == end) continue;
            spansToRemove.add(span);
        }
        for (T span : spansToRemove) {
            text.removeSpan(span);
        }
    }