Skip to content

Commit 69865bd

Browse files
author
Gilles Debunne
committed
Minor changes in SpellCheckSpan pool management in SpellChecker
Bug 6464190 The 'inProgress' flag is set to false when the SpellCheckSpan starts to get used (instead of a less intuitive when it is removed). Pool recycling in handled by onSpellCheckSpanRemoved, called from the TextView's SpanWatcher, when a SpellCheckSpan is removed for any reason (from the SC code or due to text editing). The other change is that Sentence SC now correctly removes the span from the text (and hence recycles it in the pool). Change-Id: If8b433fd5e41d4dc0304a127ebcc088ea1eecaa7
1 parent 3fcf1c8 commit 69865bd

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
}
@@ -357,6 +356,7 @@ public void onGetSuggestions(SuggestionsInfo[] results) {
357356
final SpellCheckSpan spellCheckSpan =
358357
onGetSuggestionsInternal(results[i], USE_SPAN_RANGE, USE_SPAN_RANGE);
359358
if (spellCheckSpan != null) {
359+
// onSpellCheckSpanRemoved will recycle this span in the pool
360360
editable.removeSpan(spellCheckSpan);
361361
}
362362
}
@@ -384,11 +384,12 @@ public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
384384
suggestionsInfo, offset, length);
385385
if (spellCheckSpan == null && scs != null) {
386386
// the spellCheckSpan is shared by all the "SuggestionsInfo"s in the same
387-
// SentenceSuggestionsInfo
387+
// SentenceSuggestionsInfo. Removal is deferred after this loop.
388388
spellCheckSpan = scs;
389389
}
390390
}
391391
if (spellCheckSpan != null) {
392+
// onSpellCheckSpanRemoved will recycle this span in the pool
392393
editable.removeSpan(spellCheckSpan);
393394
}
394395
}
@@ -595,7 +596,8 @@ public void parse() {
595596
}
596597
break;
597598
}
598-
removeSpellCheckSpan(spellCheckSpan);
599+
// This spellCheckSpan is replaced by the one we are creating
600+
editable.removeSpan(spellCheckSpan);
599601
spellCheckStart = Math.min(spanStart, spellCheckStart);
600602
spellCheckEnd = Math.max(spanEnd, spellCheckEnd);
601603
}

core/java/android/widget/TextView.java

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

72157215
if (mEditor != null && mEditor.mSpellChecker != null && newStart < 0 &&
72167216
what instanceof SpellCheckSpan) {
7217-
mEditor.mSpellChecker.removeSpellCheckSpan((SpellCheckSpan) what);
7217+
mEditor.mSpellChecker.onSpellCheckSpanRemoved((SpellCheckSpan) what);
72187218
}
72197219
}
72207220

0 commit comments

Comments
 (0)