summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mady Mellor <madym@google.com> 2015-06-17 09:46:01 -0700
committer Mady Mellor <madym@google.com> 2015-06-17 09:46:01 -0700
commitf9f8aebdc697e6ea1deff1aa82d0cec0e1ebacef (patch)
treee24a32f06b72d47136e80b609771840e75400823
parent13e54ff0ebc5fe6f425c16d9d30ea9ecd5db1348 (diff)
Drag to select text: add some slop for moving between lines
It's pretty easy to accidentally move to a different line when selecting text. This CL makes an adjustment so that if the user is on a line, they must move above the top of it + slop to move up a line, and they must move below the bottom of it + slop to move down a line. This applies the changes to the drag accelerator. This CL also makes an adjustment to not apply the finger offset to the drag accelerator until the user has moved lines, this was causing an issue where it would immediately include the above line when initiating the selection. Bug: 21306433 Bug: 21303943 Change-Id: Id240136493f62524fe6445d8bd65479084fe8126
-rw-r--r--core/java/android/widget/Editor.java44
1 files changed, 35 insertions, 9 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 2c989619abb8..952dd9c37746 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -4413,6 +4413,10 @@ public class Editor {
// Indicates whether the user is selecting text and using the drag accelerator.
private boolean mDragAcceleratorActive;
private boolean mHaventMovedEnoughToStartDrag;
+ // The line that a selection happened most recently with the drag accelerator.
+ private int mLineSelectionIsOn = -1;
+ // Whether the drag accelerator has selected past the initial line.
+ private boolean mSwitchedLines = false;
SelectionModifierCursorController() {
resetTouchOffsets();
@@ -4465,6 +4469,7 @@ public class Editor {
// Start location of selection.
mStartOffset = mTextView.getOffsetForPosition(mLastDownPositionX,
mLastDownPositionY);
+ mLineSelectionIsOn = mTextView.getLineAtCoordinate(mLastDownPositionY);
// Don't show the handles until user has lifted finger.
hide();
@@ -4548,17 +4553,35 @@ public class Editor {
break;
}
- if (mStartOffset != -1) {
+ if (mStartOffset != -1 && mTextView.getLayout() != null) {
if (!mHaventMovedEnoughToStartDrag) {
- // Offset the finger by the same vertical offset as the handles. This
- // improves visibility of the content being selected by shifting
- // the finger below the content.
- final float fingerOffset = (mStartHandle != null)
- ? mStartHandle.getIdealVerticalOffset()
- : touchSlop;
- int offset =
- mTextView.getOffsetForPosition(eventX, eventY - fingerOffset);
+
+ float y = eventY;
+ if (mSwitchedLines) {
+ // Offset the finger by the same vertical offset as the handles.
+ // This improves visibility of the content being selected by
+ // shifting the finger below the content, this is applied once
+ // the user has switched lines.
+ final float fingerOffset = (mStartHandle != null)
+ ? mStartHandle.getIdealVerticalOffset()
+ : touchSlop;
+ y = eventY - fingerOffset;
+ }
+
+ final int currLine = getCurrentLineAdjustedForSlop(
+ mTextView.getLayout(),
+ mLineSelectionIsOn, y);
+ if (!mSwitchedLines && currLine != mLineSelectionIsOn) {
+ // Break early here, we want to offset the finger position from
+ // the selection highlight, once the user moved their finger
+ // to a different line we should apply the offset and *not* switch
+ // lines until recomputing the position with the finger offset.
+ mSwitchedLines = true;
+ break;
+ }
+
int startOffset;
+ int offset = mTextView.getOffsetAtCoordinate(currLine, eventX);
// Snap to word boundaries.
if (mStartOffset < offset) {
// Expanding with end handle.
@@ -4569,6 +4592,7 @@ public class Editor {
offset = getWordStart(offset);
startOffset = getWordEnd(mStartOffset);
}
+ mLineSelectionIsOn = currLine;
Selection.setSelection((Spannable) mTextView.getText(),
startOffset, offset);
}
@@ -4605,6 +4629,7 @@ public class Editor {
startSelectionActionMode();
mDragAcceleratorActive = false;
mStartOffset = -1;
+ mSwitchedLines = false;
}
break;
}
@@ -4634,6 +4659,7 @@ public class Editor {
mMinTouchOffset = mMaxTouchOffset = -1;
mStartOffset = -1;
mDragAcceleratorActive = false;
+ mSwitchedLines = false;
}
/**