From 27d6b97f635bba781f4979093b82b7f6198cdeb9 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 12 Mar 2015 11:01:43 -0700 Subject: [PATCH] Fix negative touch word offset that caused crashing when selecting text Previously the offset between the touch event and the start / end of the word could result in a negative value - we don't care or want this value to be negative. The negative value also causes the returned offset to be outside the bounds of the text which resulted in a crash. Bug: 19705184 Change-Id: I4287df7778c246dd10654f1a1f1e57538e940730 --- core/java/android/widget/Editor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 5d519ed2894d1..047432c55d294 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -3850,7 +3850,7 @@ public class Editor { } } mPrevOffset = offset; - mTouchWordOffset = trueOffset - offset; + mTouchWordOffset = Math.max(trueOffset - offset, 0); mInWord = !isStartBoundary(offset); positionCursor = true; } else if (offset - mTouchWordOffset > mPrevOffset) { @@ -3954,7 +3954,7 @@ public class Editor { } } mPrevOffset = offset; - mTouchWordOffset = offset - trueOffset; + mTouchWordOffset = Math.max(offset - trueOffset, 0); mInWord = !isEndBoundary(offset); positionCursor = true; } else if (offset + mTouchWordOffset < mPrevOffset) {