|
24 | 24 | import android.text.method.WordIterator; |
25 | 25 | import android.text.style.SpellCheckSpan; |
26 | 26 | import android.text.style.SuggestionSpan; |
| 27 | +import android.util.Log; |
27 | 28 | import android.view.textservice.SentenceSuggestionsInfo; |
28 | 29 | import android.view.textservice.SpellCheckerSession; |
29 | 30 | import android.view.textservice.SpellCheckerSession.SpellCheckerSessionListener; |
|
43 | 44 | * @hide |
44 | 45 | */ |
45 | 46 | public class SpellChecker implements SpellCheckerSessionListener { |
| 47 | + private static final String TAG = SpellChecker.class.getSimpleName(); |
| 48 | + private static final boolean DBG = false; |
46 | 49 |
|
47 | 50 | // No more than this number of words will be parsed on each iteration to ensure a minimum |
48 | 51 | // lock of the UI thread |
@@ -266,6 +269,12 @@ private void spellCheck() { |
266 | 269 | editable.subSequence(start, end).toString(); |
267 | 270 | spellCheckSpan.setSpellCheckInProgress(true); |
268 | 271 | textInfos[textInfosCount++] = new TextInfo(word, mCookie, mIds[i]); |
| 272 | + if (DBG) { |
| 273 | + Log.d(TAG, "create TextInfo: (" + i + "/" + mLength + ")" + word |
| 274 | + + ", cookie = " + mCookie + ", seq = " |
| 275 | + + mIds[i] + ", sel start = " + selectionStart + ", sel end = " |
| 276 | + + selectionEnd + ", start = " + start + ", end = " + end); |
| 277 | + } |
269 | 278 | } |
270 | 279 | } |
271 | 280 |
|
@@ -507,7 +516,20 @@ public void parse() { |
507 | 516 | if (regionEnd <= spellCheckStart) { |
508 | 517 | return; |
509 | 518 | } |
510 | | - addSpellCheckSpan(editable, spellCheckStart, regionEnd); |
| 519 | + final int selectionStart = Selection.getSelectionStart(editable); |
| 520 | + final int selectionEnd = Selection.getSelectionEnd(editable); |
| 521 | + if (DBG) { |
| 522 | + Log.d(TAG, "addSpellCheckSpan: " |
| 523 | + + editable.subSequence(spellCheckStart, regionEnd) |
| 524 | + + ", regionEnd = " + regionEnd + ", spellCheckStart = " |
| 525 | + + spellCheckStart + ", sel start = " + selectionStart + ", sel end =" |
| 526 | + + selectionEnd); |
| 527 | + } |
| 528 | + // Do not check this word if the user is currently editing it |
| 529 | + if (spellCheckStart >= 0 && regionEnd > spellCheckStart |
| 530 | + && (selectionEnd < spellCheckStart || selectionStart > regionEnd)) { |
| 531 | + addSpellCheckSpan(editable, spellCheckStart, regionEnd); |
| 532 | + } |
511 | 533 | } else { |
512 | 534 | while (wordStart <= end) { |
513 | 535 | if (wordEnd >= start && wordEnd > wordStart) { |
|
0 commit comments