diff options
author | Gilles Debunne <debunne@google.com> | 2011-11-29 15:25:03 -0800 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2011-11-29 18:05:05 -0800 |
commit | 8615ac9e049cdf4ab77b0897aca9bceec142c9fa (patch) | |
tree | 639230ea30af214c79e8684f95f6c2fb3f0e3afc /core/java/android/widget/SpellChecker.java | |
parent | 9b518d9304eb4ad17591944926231b661a3dfce0 (diff) | |
download | frameworks_base-8615ac9e049cdf4ab77b0897aca9bceec142c9fa.zip frameworks_base-8615ac9e049cdf4ab77b0897aca9bceec142c9fa.tar.gz frameworks_base-8615ac9e049cdf4ab77b0897aca9bceec142c9fa.tar.bz2 |
Invalidated bounds tightened in TextView
New invalidateRegion method, with better horizontal invalidate
bounds in case the region is on one line.
Use by SpellChecker when a new SuggestionSpan is added.
Change-Id: Ide11f1d3d2b1350032b475db0641018a49c08d13
Diffstat (limited to 'core/java/android/widget/SpellChecker.java')
-rw-r--r-- | core/java/android/widget/SpellChecker.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java index ebb2604..bc46126 100644 --- a/core/java/android/widget/SpellChecker.java +++ b/core/java/android/widget/SpellChecker.java @@ -258,9 +258,11 @@ public class SpellChecker implements SpellCheckerSessionListener { ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0); SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j]; + if (!isInDictionary && looksLikeTypo) { createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan); } + editable.removeSpan(spellCheckSpan); break; } @@ -276,20 +278,21 @@ public class SpellChecker implements SpellCheckerSessionListener { } } - private void createMisspelledSuggestionSpan(Editable editable, - SuggestionsInfo suggestionsInfo, SpellCheckSpan spellCheckSpan) { + private void createMisspelledSuggestionSpan(Editable editable, SuggestionsInfo suggestionsInfo, + SpellCheckSpan spellCheckSpan) { final int start = editable.getSpanStart(spellCheckSpan); final int end = editable.getSpanEnd(spellCheckSpan); - if (start < 0 || end < 0) return; // span was removed in the meantime + if (start < 0 || end <= start) return; // span was removed in the meantime // Other suggestion spans may exist on that region, with identical suggestions, filter - // them out to avoid duplicates. First, filter suggestion spans on that exact region. + // them out to avoid duplicates. SuggestionSpan[] suggestionSpans = editable.getSpans(start, end, SuggestionSpan.class); final int length = suggestionSpans.length; for (int i = 0; i < length; i++) { final int spanStart = editable.getSpanStart(suggestionSpans[i]); final int spanEnd = editable.getSpanEnd(suggestionSpans[i]); if (spanStart != start || spanEnd != end) { + // Nulled (to avoid new array allocation) if not on that exact same region suggestionSpans[i] = null; } } @@ -337,8 +340,7 @@ public class SpellChecker implements SpellCheckerSessionListener { SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED); editable.setSpan(suggestionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - // TODO limit to the word rectangle region - mTextView.invalidate(); + mTextView.invalidateRegion(start, end); } private class SpellParser { |