Skip to content

Commit 0ed59fa

Browse files
author
Fabrice Di Meglio
committed
Fix bug #6567507 [Bidi] - Cursor is sometimes not visible on EditText
- take the hint layout primary horizontal offset if needed Change-Id: Ib5c4dd990278e1fd8bb9ba4f4b6940a62dba91e3
1 parent 73bde11 commit 0ed59fa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

core/java/android/widget/Editor.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ void updateCursorsPositions() {
14161416
}
14171417

14181418
Layout layout = mTextView.getLayout();
1419+
Layout hintLayout = mTextView.getHintLayout();
14191420
final int offset = mTextView.getSelectionStart();
14201421
final int line = layout.getLineForOffset(offset);
14211422
final int top = layout.getLineTop(line);
@@ -1429,13 +1430,23 @@ void updateCursorsPositions() {
14291430
middle = (top + bottom) >> 1;
14301431
}
14311432

1432-
updateCursorPosition(0, top, middle, layout.getPrimaryHorizontal(offset));
1433+
updateCursorPosition(0, top, middle, getPrimaryHorizontal(layout, hintLayout, offset));
14331434

14341435
if (mCursorCount == 2) {
14351436
updateCursorPosition(1, middle, bottom, layout.getSecondaryHorizontal(offset));
14361437
}
14371438
}
14381439

1440+
private float getPrimaryHorizontal(Layout layout, Layout hintLayout, int offset) {
1441+
if (TextUtils.isEmpty(layout.getText()) &&
1442+
hintLayout != null &&
1443+
!TextUtils.isEmpty(hintLayout.getText())) {
1444+
return hintLayout.getPrimaryHorizontal(offset);
1445+
} else {
1446+
return layout.getPrimaryHorizontal(offset);
1447+
}
1448+
}
1449+
14391450
/**
14401451
* @return true if the selection mode was actually started.
14411452
*/

core/java/android/widget/TextView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,14 @@ public final Layout getLayout() {
13111311
return mLayout;
13121312
}
13131313

1314+
/**
1315+
* @return the Layout that is currently being used to display the hint text.
1316+
* This can be null.
1317+
*/
1318+
final Layout getHintLayout() {
1319+
return mHintLayout;
1320+
}
1321+
13141322
/**
13151323
* @return the current key listener for this TextView.
13161324
* This will frequently be null for non-EditText TextViews.

0 commit comments

Comments
 (0)