am 0caf421e: Merge "Final fix in SpannableStringBuilder." into jb-dev
* commit '0caf421e3aacea928f2ce0e99e101a6584127527': Final fix in SpannableStringBuilder.
This commit is contained in:
@@ -308,6 +308,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
|
|||||||
resizeFor(mText.length + nbNewChars - mGapLength);
|
resizeFor(mText.length + nbNewChars - mGapLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean textIsRemoved = replacementLength == 0;
|
||||||
// The removal pass needs to be done before the gap is updated in order to broadcast the
|
// The removal pass needs to be done before the gap is updated in order to broadcast the
|
||||||
// correct previous positions to the correct intersecting SpanWatchers
|
// correct previous positions to the correct intersecting SpanWatchers
|
||||||
if (replacedLength > 0) { // no need for span fixup on pure insertion
|
if (replacedLength > 0) { // no need for span fixup on pure insertion
|
||||||
@@ -320,11 +321,14 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
|
|||||||
if ((mSpanFlags[i] & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) ==
|
if ((mSpanFlags[i] & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) ==
|
||||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE &&
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE &&
|
||||||
mSpanStarts[i] >= start && mSpanStarts[i] < mGapStart + mGapLength &&
|
mSpanStarts[i] >= start && mSpanStarts[i] < mGapStart + mGapLength &&
|
||||||
mSpanEnds[i] >= start && mSpanEnds[i] < mGapStart + mGapLength) {
|
mSpanEnds[i] >= start && mSpanEnds[i] < mGapStart + mGapLength &&
|
||||||
|
// This condition indicates that the span would become empty
|
||||||
|
(textIsRemoved || mSpanStarts[i] > start || mSpanEnds[i] < mGapStart)) {
|
||||||
removeSpan(i);
|
removeSpan(i);
|
||||||
} else {
|
continue; // do not increment i, spans will be shifted left in the array
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +342,6 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
|
|||||||
|
|
||||||
if (replacedLength > 0) { // no need for span fixup on pure insertion
|
if (replacedLength > 0) { // no need for span fixup on pure insertion
|
||||||
final boolean atEnd = (mGapStart + mGapLength == mText.length);
|
final boolean atEnd = (mGapStart + mGapLength == mText.length);
|
||||||
final boolean textIsRemoved = replacementLength == 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < mSpanCount; i++) {
|
for (int i = 0; i < mSpanCount; i++) {
|
||||||
final int startFlag = (mSpanFlags[i] & START_MASK) >> START_SHIFT;
|
final int startFlag = (mSpanFlags[i] & START_MASK) >> START_SHIFT;
|
||||||
@@ -390,9 +393,9 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
|
|||||||
return mGapStart + mGapLength;
|
return mGapStart + mGapLength;
|
||||||
}
|
}
|
||||||
} else { // MARK
|
} else { // MARK
|
||||||
// MARKs should be moved to the start, with the exception of a mark located at the
|
// MARKs should be moved to the start, with the exception of a mark located at
|
||||||
// end of the range (which will be < mGapStart + mGapLength since mGapLength > 0)
|
// the end of the range (which will be < mGapStart + mGapLength since mGapLength
|
||||||
// which should stay 'unchanged' at the end of the replaced text.
|
// is > 0, which should stay 'unchanged' at the end of the replaced text.
|
||||||
if (textIsRemoved || offset < mGapStart - nbNewChars) {
|
if (textIsRemoved || offset < mGapStart - nbNewChars) {
|
||||||
return start;
|
return start;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user