Skip to content

Commit e1e8748

Browse files
committed
Optimize the timing to query sentence level spell checking
Bug: 6354647 Change-Id: I52e6c21387c7f4d6fc05b4c50bbb0a5a6c75194b
1 parent cdd9d43 commit e1e8748

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

core/java/android/widget/SpellChecker.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.text.method.WordIterator;
2525
import android.text.style.SpellCheckSpan;
2626
import android.text.style.SuggestionSpan;
27+
import android.util.Log;
2728
import android.view.textservice.SentenceSuggestionsInfo;
2829
import android.view.textservice.SpellCheckerSession;
2930
import android.view.textservice.SpellCheckerSession.SpellCheckerSessionListener;
@@ -43,6 +44,8 @@
4344
* @hide
4445
*/
4546
public class SpellChecker implements SpellCheckerSessionListener {
47+
private static final String TAG = SpellChecker.class.getSimpleName();
48+
private static final boolean DBG = false;
4649

4750
// No more than this number of words will be parsed on each iteration to ensure a minimum
4851
// lock of the UI thread
@@ -266,6 +269,12 @@ private void spellCheck() {
266269
editable.subSequence(start, end).toString();
267270
spellCheckSpan.setSpellCheckInProgress(true);
268271
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+
}
269278
}
270279
}
271280

@@ -507,7 +516,20 @@ public void parse() {
507516
if (regionEnd <= spellCheckStart) {
508517
return;
509518
}
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+
}
511533
} else {
512534
while (wordStart <= end) {
513535
if (wordEnd >= start && wordEnd > wordStart) {

0 commit comments

Comments
 (0)