Skip to content

Commit 855f540

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "Minor changes in SpellCheckSpan pool management in SpellChecker" into jb-dev
2 parents 7b8523a + 69865bd commit 855f540

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

core/java/android/widget/SpellChecker.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ private void resetSession() {
132132

133133
// Restore SpellCheckSpans in pool
134134
for (int i = 0; i < mLength; i++) {
135-
// Resets id and progress to invalidate spell check span
136-
mSpellCheckSpans[i].setSpellCheckInProgress(false);
137135
mIds[i] = -1;
138136
}
139137
mLength = 0;
@@ -200,15 +198,16 @@ private int nextSpellCheckSpanIndex() {
200198

201199
private void addSpellCheckSpan(Editable editable, int start, int end) {
202200
final int index = nextSpellCheckSpanIndex();
203-
editable.setSpan(mSpellCheckSpans[index], start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
201+
SpellCheckSpan spellCheckSpan = mSpellCheckSpans[index];
202+
editable.setSpan(spellCheckSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
203+
spellCheckSpan.setSpellCheckInProgress(false);
204204
mIds[index] = mSpanSequenceCounter++;
205205
}
206206

207-
public void removeSpellCheckSpan(SpellCheckSpan spellCheckSpan) {
207+
public void onSpellCheckSpanRemoved(SpellCheckSpan spellCheckSpan) {
208+
// Recycle any removed SpellCheckSpan (from this code or during text edition)
208209
for (int i = 0; i < mLength; i++) {
209210
if (mSpellCheckSpans[i] == spellCheckSpan) {
210-
// Resets id and progress to invalidate spell check span
211-
mSpellCheckSpans[i].setSpellCheckInProgress(false);
212211
mIds[i] = -1;
213212
return;
214213
}
@@ -387,6 +386,7 @@ public void onGetSuggestions(SuggestionsInfo[] results) {
387386
final SpellCheckSpan spellCheckSpan =
388387
onGetSuggestionsInternal(results[i], USE_SPAN_RANGE, USE_SPAN_RANGE);
389388
if (spellCheckSpan != null) {
389+
// onSpellCheckSpanRemoved will recycle this span in the pool
390390
editable.removeSpan(spellCheckSpan);
391391
}
392392
}
@@ -414,11 +414,12 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
414414
suggestionsInfo, offset, length);
415415
if (spellCheckSpan == null && scs != null) {
416416
// the spellCheckSpan is shared by all the "SuggestionsInfo"s in the same
417-
// SentenceSuggestionsInfo
417+
// SentenceSuggestionsInfo. Removal is deferred after this loop.
418418
spellCheckSpan = scs;
419419
}
420420
}
421421
if (spellCheckSpan != null) {
422+
// onSpellCheckSpanRemoved will recycle this span in the pool
422423
editable.removeSpan(spellCheckSpan);
423424
}
424425
}
@@ -633,7 +634,8 @@ public void parse() {
633634
}
634635
break;
635636
}
636-
removeSpellCheckSpan(spellCheckSpan);
637+
// This spellCheckSpan is replaced by the one we are creating
638+
editable.removeSpan(spellCheckSpan);
637639
spellCheckStart = Math.min(spanStart, spellCheckStart);
638640
spellCheckEnd = Math.max(spanEnd, spellCheckEnd);
639641
}

core/java/android/widget/TextView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7240,7 +7240,7 @@ void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd
72407240

72417241
if (mEditor != null && mEditor.mSpellChecker != null && newStart < 0 &&
72427242
what instanceof SpellCheckSpan) {
7243-
mEditor.mSpellChecker.removeSpellCheckSpan((SpellCheckSpan) what);
7243+
mEditor.mSpellChecker.onSpellCheckSpanRemoved((SpellCheckSpan) what);
72447244
}
72457245
}
72467246

0 commit comments

Comments
 (0)