@@ -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