Merge "Bug 5295607: IOOB problems in Suggestions"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a4102b972e
@@ -9617,10 +9617,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SuggestionInfo {
|
private class SuggestionInfo {
|
||||||
int suggestionStart, suggestionEnd; // range of suggestion item with replacement text
|
int suggestionStart, suggestionEnd; // range of actual suggestion within text
|
||||||
int spanStart, spanEnd; // range in TextView where text should be inserted
|
|
||||||
SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents
|
SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents
|
||||||
int suggestionIndex; // the index of the suggestion inside suggestionSpan
|
int suggestionIndex; // the index of this suggestion inside suggestionSpan
|
||||||
SpannableStringBuilder text = new SpannableStringBuilder();
|
SpannableStringBuilder text = new SpannableStringBuilder();
|
||||||
TextAppearanceSpan highlightSpan = new TextAppearanceSpan(mContext,
|
TextAppearanceSpan highlightSpan = new TextAppearanceSpan(mContext,
|
||||||
android.R.style.TextAppearance_SuggestionHighlight);
|
android.R.style.TextAppearance_SuggestionHighlight);
|
||||||
@@ -9804,8 +9803,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
int nbSuggestions = suggestions.length;
|
int nbSuggestions = suggestions.length;
|
||||||
for (int suggestionIndex = 0; suggestionIndex < nbSuggestions; suggestionIndex++) {
|
for (int suggestionIndex = 0; suggestionIndex < nbSuggestions; suggestionIndex++) {
|
||||||
SuggestionInfo suggestionInfo = mSuggestionInfos[mNumberOfSuggestions];
|
SuggestionInfo suggestionInfo = mSuggestionInfos[mNumberOfSuggestions];
|
||||||
suggestionInfo.spanStart = spanStart;
|
|
||||||
suggestionInfo.spanEnd = spanEnd;
|
|
||||||
suggestionInfo.suggestionSpan = suggestionSpan;
|
suggestionInfo.suggestionSpan = suggestionSpan;
|
||||||
suggestionInfo.suggestionIndex = suggestionIndex;
|
suggestionInfo.suggestionIndex = suggestionIndex;
|
||||||
suggestionInfo.text.replace(0, suggestionInfo.text.length(),
|
suggestionInfo.text.replace(0, suggestionInfo.text.length(),
|
||||||
@@ -9829,8 +9826,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
final int misspelledEnd = spannable.getSpanEnd(misspelledSpan);
|
final int misspelledEnd = spannable.getSpanEnd(misspelledSpan);
|
||||||
if (misspelledStart >= 0 && misspelledEnd > misspelledStart) {
|
if (misspelledStart >= 0 && misspelledEnd > misspelledStart) {
|
||||||
SuggestionInfo suggestionInfo = mSuggestionInfos[mNumberOfSuggestions];
|
SuggestionInfo suggestionInfo = mSuggestionInfos[mNumberOfSuggestions];
|
||||||
suggestionInfo.spanStart = misspelledStart;
|
|
||||||
suggestionInfo.spanEnd = misspelledEnd;
|
|
||||||
suggestionInfo.suggestionSpan = misspelledSpan;
|
suggestionInfo.suggestionSpan = misspelledSpan;
|
||||||
suggestionInfo.suggestionIndex = -1;
|
suggestionInfo.suggestionIndex = -1;
|
||||||
suggestionInfo.text.replace(0, suggestionInfo.text.length(),
|
suggestionInfo.text.replace(0, suggestionInfo.text.length(),
|
||||||
@@ -9862,8 +9857,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
private void highlightTextDifferences(SuggestionInfo suggestionInfo, int unionStart,
|
private void highlightTextDifferences(SuggestionInfo suggestionInfo, int unionStart,
|
||||||
int unionEnd) {
|
int unionEnd) {
|
||||||
final int spanStart = suggestionInfo.spanStart;
|
final Spannable text = (Spannable) mText;
|
||||||
final int spanEnd = suggestionInfo.spanEnd;
|
final int spanStart = text.getSpanStart(suggestionInfo.suggestionSpan);
|
||||||
|
final int spanEnd = text.getSpanEnd(suggestionInfo.suggestionSpan);
|
||||||
|
|
||||||
// Adjust the start/end of the suggestion span
|
// Adjust the start/end of the suggestion span
|
||||||
suggestionInfo.suggestionStart = spanStart - unionStart;
|
suggestionInfo.suggestionStart = spanStart - unionStart;
|
||||||
@@ -9883,10 +9879,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (view instanceof TextView) {
|
if (view instanceof TextView) {
|
||||||
TextView textView = (TextView) view;
|
TextView textView = (TextView) view;
|
||||||
|
Editable editable = (Editable) mText;
|
||||||
|
|
||||||
SuggestionInfo suggestionInfo = mSuggestionInfos[position];
|
SuggestionInfo suggestionInfo = mSuggestionInfos[position];
|
||||||
final int spanStart = suggestionInfo.spanStart;
|
final int spanStart = editable.getSpanStart(suggestionInfo.suggestionSpan);
|
||||||
final int spanEnd = suggestionInfo.spanEnd;
|
final int spanEnd = editable.getSpanEnd(suggestionInfo.suggestionSpan);
|
||||||
final String originalText = mText.subSequence(spanStart, spanEnd).toString();
|
final String originalText = mText.subSequence(spanStart, spanEnd).toString();
|
||||||
|
|
||||||
if (suggestionInfo.suggestionIndex < 0) {
|
if (suggestionInfo.suggestionIndex < 0) {
|
||||||
@@ -9897,7 +9894,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
suggestionInfo.removeMisspelledFlag();
|
suggestionInfo.removeMisspelledFlag();
|
||||||
} else {
|
} else {
|
||||||
// SuggestionSpans are removed by replace: save them before
|
// SuggestionSpans are removed by replace: save them before
|
||||||
Editable editable = (Editable) mText;
|
|
||||||
SuggestionSpan[] suggestionSpans = editable.getSpans(spanStart, spanEnd,
|
SuggestionSpan[] suggestionSpans = editable.getSpans(spanStart, spanEnd,
|
||||||
SuggestionSpan.class);
|
SuggestionSpan.class);
|
||||||
final int length = suggestionSpans.length;
|
final int length = suggestionSpans.length;
|
||||||
|
|||||||
Reference in New Issue
Block a user