Skip to content

Commit 961ebb9

Browse files
author
Gilles Debunne
committed
Text blinking cursor hard to see.
Bug 5738416 This problem was introduced in https://android-git.corp.google.com/g/#/c/152599 The invalidated cursor region is no longer expanded to include the cursor drawable (different from the handles' drawables). Added that code back. Added a flag, since invalidateRegion is also used to invalidate text span regions in spell check (assumes the decorated span bounds are not bigger that text boundaries), which is fine in case of underline. When the cursor is moved on a single line, invalidate the whole line (same as what was done before). This is sub-optimal, will file a bug to fix this. The core problem is that we should invalidate the previous and the new cursor's positions. We only have one of these. Change-Id: I9ada9340fb52aad3d80c39efd021fd3f9ec0cc4d
1 parent caf4ead commit 961ebb9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

core/java/android/widget/SpellChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private void createMisspelledSuggestionSpan(Editable editable, SuggestionsInfo s
393393
SuggestionSpan.FLAG_EASY_CORRECT | SuggestionSpan.FLAG_MISSPELLED);
394394
editable.setSpan(suggestionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
395395

396-
mTextView.invalidateRegion(start, end);
396+
mTextView.invalidateRegion(start, end, false /* No cursor involved */);
397397
}
398398

399399
private class SpellParser {

core/java/android/widget/TextView.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static class InputMethodState {
339339

340340
private int mCursorDrawableRes;
341341
private final Drawable[] mCursorDrawable = new Drawable[2];
342-
private int mCursorCount; // Actual current number of used mCursorDrawable: 0, 1 or 2
342+
private int mCursorCount; // Actual current number of used mCursorDrawable: 0, 1 or 2 (split)
343343

344344
private Drawable mSelectHandleLeft;
345345
private Drawable mSelectHandleRight;
@@ -4322,7 +4322,7 @@ private void invalidateCursor(int a, int b, int c) {
43224322
if (a >= 0 || b >= 0 || c >= 0) {
43234323
int start = Math.min(Math.min(a, b), c);
43244324
int end = Math.max(Math.max(a, b), c);
4325-
invalidateRegion(start, end);
4325+
invalidateRegion(start, end, true /* Also invalidates blinking cursor */);
43264326
}
43274327
}
43284328

@@ -4331,7 +4331,7 @@ private void invalidateCursor(int a, int b, int c) {
43314331
*
43324332
* @hide
43334333
*/
4334-
void invalidateRegion(int start, int end) {
4334+
void invalidateRegion(int start, int end, boolean invalidateCursor) {
43354335
if (mLayout == null) {
43364336
invalidate();
43374337
} else {
@@ -4357,11 +4357,19 @@ void invalidateRegion(int start, int end) {
43574357

43584358
int bottom = mLayout.getLineBottom(lineEnd);
43594359

4360+
if (invalidateCursor) {
4361+
for (int i = 0; i < mCursorCount; i++) {
4362+
Rect bounds = mCursorDrawable[i].getBounds();
4363+
top = Math.min(top, bounds.top);
4364+
bottom = Math.max(bottom, bounds.bottom);
4365+
}
4366+
}
4367+
43604368
final int compoundPaddingLeft = getCompoundPaddingLeft();
43614369
final int verticalPadding = getExtendedPaddingTop() + getVerticalOffset(true);
43624370

43634371
int left, right;
4364-
if (lineStart == lineEnd) {
4372+
if (lineStart == lineEnd && !invalidateCursor) {
43654373
left = (int) mLayout.getPrimaryHorizontal(start);
43664374
right = (int) (mLayout.getPrimaryHorizontal(end) + 1.0);
43674375
left += compoundPaddingLeft;

0 commit comments

Comments
 (0)