Skip to content

Commit bec154c

Browse files
committed
Allow the spell checker to remove existing misspelled spans
Bug: 6451163 Change-Id: If018533e8855e9dc21ab2a09ae31aa80ef260b72
1 parent e9aa4b2 commit bec154c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

core/java/android/widget/SpellChecker.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,36 @@ private SpellCheckSpan onGetSuggestionsInternal(
343343
if (!isInDictionary && looksLikeTypo) {
344344
createMisspelledSuggestionSpan(
345345
editable, suggestionsInfo, spellCheckSpan, offset, length);
346+
} else {
347+
// Valid word -- isInDictionary || !looksLikeTypo
348+
if (mIsSentenceSpellCheckSupported) {
349+
// Allow the spell checker to remove existing misspelled span by
350+
// overwriting the span over the same place
351+
final int spellCheckSpanStart = editable.getSpanStart(spellCheckSpan);
352+
final int spellCheckSpanEnd = editable.getSpanEnd(spellCheckSpan);
353+
final int start;
354+
final int end;
355+
if (offset != USE_SPAN_RANGE && length != USE_SPAN_RANGE) {
356+
start = spellCheckSpanStart + offset;
357+
end = start + length;
358+
} else {
359+
start = spellCheckSpanStart;
360+
end = spellCheckSpanEnd;
361+
}
362+
if (spellCheckSpanStart >= 0 && spellCheckSpanEnd > spellCheckSpanStart
363+
&& end > start) {
364+
final Long key = Long.valueOf(TextUtils.packRangeInLong(start, end));
365+
final SuggestionSpan tempSuggestionSpan = mSuggestionSpanCache.get(key);
366+
if (tempSuggestionSpan != null) {
367+
if (DBG) {
368+
Log.i(TAG, "Remove existing misspelled span. "
369+
+ editable.subSequence(start, end));
370+
}
371+
editable.removeSpan(tempSuggestionSpan);
372+
mSuggestionSpanCache.remove(key);
373+
}
374+
}
375+
}
346376
}
347377
return spellCheckSpan;
348378
}

0 commit comments

Comments
 (0)