From 44cb2432e90c7a9e0ee59b959d781ba8834c1736 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 13 Nov 2014 12:36:49 -0800 Subject: [PATCH] Fudge clipRect in TextView for extra cursor width There are a number of cases (most commonly cursor at start of line in RTL direction) where the cursor extends past the right edge of the clipRect. This patch adds approximately 1dp on the right side of the clip, so that the cursor doesn't get clipped. Bug: 18035274 Change-Id: I489825a91750742c28e445f54f9d27000accbcfb --- core/java/android/widget/TextView.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 0917b32e89d48..b67bbdb62b402 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -5368,9 +5368,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final int vspace = mBottom - mTop - compoundPaddingBottom - compoundPaddingTop; final int maxScrollY = mLayout.getHeight() - vspace; + // Add sufficient space for cursor and tone marks + int cursorWidth = 2 + (int)mTextPaint.density; // adequate for Material cursors + int fudgedPaddingRight = Math.max(0, compoundPaddingRight - (cursorWidth - 1)); + float clipLeft = compoundPaddingLeft + scrollX; float clipTop = (scrollY == 0) ? 0 : extendedPaddingTop + scrollY; - float clipRight = right - left - compoundPaddingRight + scrollX; + float clipRight = right - left - fudgedPaddingRight + scrollX; float clipBottom = bottom - top + scrollY - ((scrollY == maxScrollY) ? 0 : extendedPaddingBottom);