@@ -4323,52 +4323,61 @@ private void invalidateCursor() {
43234323 }
43244324
43254325 private void invalidateCursor (int a , int b , int c ) {
4326+ if (a >= 0 || b >= 0 || c >= 0 ) {
4327+ int start = Math .min (Math .min (a , b ), c );
4328+ int end = Math .max (Math .max (a , b ), c );
4329+ invalidateRegion (start , end );
4330+ }
4331+ }
4332+
4333+ /**
4334+ * Invalidates the region of text enclosed between the start and end text offsets.
4335+ *
4336+ * @hide
4337+ */
4338+ void invalidateRegion (int start , int end ) {
43264339 if (mLayout == null ) {
43274340 invalidate ();
43284341 } else {
4329- if (a >= 0 || b >= 0 || c >= 0 ) {
4330- int first = Math .min (Math .min (a , b ), c );
4331- int last = Math .max (Math .max (a , b ), c );
4332-
4333- int line = mLayout .getLineForOffset (first );
4334- int top = mLayout .getLineTop (line );
4342+ int lineStart = mLayout .getLineForOffset (start );
4343+ int top = mLayout .getLineTop (lineStart );
43354344
43364345 // This is ridiculous, but the descent from the line above
43374346 // can hang down into the line we really want to redraw,
43384347 // so we have to invalidate part of the line above to make
43394348 // sure everything that needs to be redrawn really is.
43404349 // (But not the whole line above, because that would cause
43414350 // the same problem with the descenders on the line above it!)
4342- if (line > 0 ) {
4343- top -= mLayout .getLineDescent (line - 1 );
4351+ if (lineStart > 0 ) {
4352+ top -= mLayout .getLineDescent (lineStart - 1 );
43444353 }
43454354
4346- int line2 ;
4355+ int lineEnd ;
43474356
4348- if (first == last )
4349- line2 = line ;
4357+ if (start == end )
4358+ lineEnd = lineStart ;
43504359 else
4351- line2 = mLayout .getLineForOffset (last );
4360+ lineEnd = mLayout .getLineForOffset (end );
43524361
4353- int bottom = mLayout .getLineTop ( line2 + 1 );
4362+ int bottom = mLayout .getLineBottom ( lineEnd );
43544363
4355- final int horizontalPadding = getCompoundPaddingLeft ();
4364+ final int compoundPaddingLeft = getCompoundPaddingLeft ();
43564365 final int verticalPadding = getExtendedPaddingTop () + getVerticalOffset (true );
4357-
4358- // If used, the cursor drawables can have an arbitrary dimension that can go beyond
4359- // the invalidated lines specified above.
4360- for (int i = 0 ; i < mCursorCount ; i ++) {
4361- Rect bounds = mCursorDrawable [i ].getBounds ();
4362- top = Math .min (top , bounds .top );
4363- bottom = Math .max (bottom , bounds .bottom );
4364- // Horizontal bounds are already full width, no need to update
4366+
4367+ int left , right ;
4368+ if (lineStart == lineEnd ) {
4369+ left = (int ) mLayout .getPrimaryHorizontal (start );
4370+ right = (int ) (mLayout .getPrimaryHorizontal (end ) + 1.0 );
4371+ left += compoundPaddingLeft ;
4372+ right += compoundPaddingLeft ;
4373+ } else {
4374+ // Rectangle bounding box when the region spans several lines
4375+ left = compoundPaddingLeft ;
4376+ right = getWidth () - getCompoundPaddingRight ();
43654377 }
43664378
4367- invalidate (horizontalPadding + mScrollX , top + verticalPadding ,
4368- horizontalPadding + mScrollX + getWidth () -
4369- getCompoundPaddingLeft () - getCompoundPaddingRight (),
4370- bottom + verticalPadding );
4371- }
4379+ invalidate (mScrollX + left , verticalPadding + top ,
4380+ mScrollX + right , verticalPadding + bottom );
43724381 }
43734382 }
43744383
@@ -5901,10 +5910,10 @@ public void draw(Canvas canvas, int cursorOffsetVertical) {
59015910 if (cursorOffsetVertical != 0 ) {
59025911 canvas .translate (0 , -cursorOffsetVertical );
59035912 }
5904- invalidate (true );
5913+ invalidate (true ); // TODO invalidate cursor region only
59055914 } else {
59065915 stopAnimation ();
5907- invalidate (false );
5916+ invalidate (false ); // TODO invalidate cursor region only
59085917 }
59095918 }
59105919
@@ -7724,10 +7733,8 @@ void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd
77247733 onSelectionChanged (newSelStart , newSelEnd );
77257734 }
77267735 }
7727-
7728- if (what instanceof UpdateAppearance || what instanceof ParagraphStyle
7729- || (what instanceof SuggestionSpan && (((SuggestionSpan )what ).getFlags ()
7730- & SuggestionSpan .FLAG_AUTO_CORRECTION ) != 0 )) {
7736+
7737+ if (what instanceof UpdateAppearance || what instanceof ParagraphStyle ) {
77317738 if (ims == null || ims .mBatchEditNesting == 0 ) {
77327739 invalidate ();
77337740 mHighlightPathBogus = true ;
0 commit comments