From ee3821e565496bd3dc470bb3f833a875b3650a20 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Fri, 5 Jun 2015 11:12:01 -0700 Subject: [PATCH] Insertion cursor: add some slop for moving between lines Applying same method to insertion cursor as the text selection drag handles to improve moving along lines. Basically adds some slop above / below the current line and only allows you to change lines if you move outside of that. Bug: 21306433 Change-Id: I6c7f3a496fbd1ea66936832f96325736cea872aa --- core/java/android/widget/Editor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 2c989619abb83..d0b616050af01 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -4013,7 +4013,15 @@ public class Editor { @Override public void updatePosition(float x, float y) { - positionAtCursorOffset(mTextView.getOffsetForPosition(x, y), false); + Layout layout = mTextView.getLayout(); + int offset; + if (layout != null) { + int currLine = getCurrentLineAdjustedForSlop(layout, mPrevLine, y); + offset = mTextView.getOffsetAtCoordinate(currLine, x); + } else { + offset = mTextView.getOffsetForPosition(x, y); + } + positionAtCursorOffset(offset, false); if (mTextActionMode != null) { mTextActionMode.invalidate(); }