Loading core/java/android/widget/Editor.java +35 −9 Original line number Original line Diff line number Diff line Loading @@ -4421,6 +4421,10 @@ public class Editor { // Indicates whether the user is selecting text and using the drag accelerator. // Indicates whether the user is selecting text and using the drag accelerator. private boolean mDragAcceleratorActive; private boolean mDragAcceleratorActive; private boolean mHaventMovedEnoughToStartDrag; 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() { SelectionModifierCursorController() { resetTouchOffsets(); resetTouchOffsets(); Loading Loading @@ -4473,6 +4477,7 @@ public class Editor { // Start location of selection. // Start location of selection. mStartOffset = mTextView.getOffsetForPosition(mLastDownPositionX, mStartOffset = mTextView.getOffsetForPosition(mLastDownPositionX, mLastDownPositionY); mLastDownPositionY); mLineSelectionIsOn = mTextView.getLineAtCoordinate(mLastDownPositionY); // Don't show the handles until user has lifted finger. // Don't show the handles until user has lifted finger. hide(); hide(); Loading Loading @@ -4556,17 +4561,35 @@ public class Editor { break; break; } } if (mStartOffset != -1) { if (mStartOffset != -1 && mTextView.getLayout() != null) { if (!mHaventMovedEnoughToStartDrag) { if (!mHaventMovedEnoughToStartDrag) { // Offset the finger by the same vertical offset as the handles. This // improves visibility of the content being selected by shifting float y = eventY; // the finger below the content. 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) final float fingerOffset = (mStartHandle != null) ? mStartHandle.getIdealVerticalOffset() ? mStartHandle.getIdealVerticalOffset() : touchSlop; : touchSlop; int offset = y = eventY - fingerOffset; mTextView.getOffsetForPosition(eventX, 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 startOffset; int offset = mTextView.getOffsetAtCoordinate(currLine, eventX); // Snap to word boundaries. // Snap to word boundaries. if (mStartOffset < offset) { if (mStartOffset < offset) { // Expanding with end handle. // Expanding with end handle. Loading @@ -4577,6 +4600,7 @@ public class Editor { offset = getWordStart(offset); offset = getWordStart(offset); startOffset = getWordEnd(mStartOffset); startOffset = getWordEnd(mStartOffset); } } mLineSelectionIsOn = currLine; Selection.setSelection((Spannable) mTextView.getText(), Selection.setSelection((Spannable) mTextView.getText(), startOffset, offset); startOffset, offset); } } Loading Loading @@ -4613,6 +4637,7 @@ public class Editor { startSelectionActionMode(); startSelectionActionMode(); mDragAcceleratorActive = false; mDragAcceleratorActive = false; mStartOffset = -1; mStartOffset = -1; mSwitchedLines = false; } } break; break; } } Loading Loading @@ -4642,6 +4667,7 @@ public class Editor { mMinTouchOffset = mMaxTouchOffset = -1; mMinTouchOffset = mMaxTouchOffset = -1; mStartOffset = -1; mStartOffset = -1; mDragAcceleratorActive = false; mDragAcceleratorActive = false; mSwitchedLines = false; } } /** /** Loading Loading
core/java/android/widget/Editor.java +35 −9 Original line number Original line Diff line number Diff line Loading @@ -4421,6 +4421,10 @@ public class Editor { // Indicates whether the user is selecting text and using the drag accelerator. // Indicates whether the user is selecting text and using the drag accelerator. private boolean mDragAcceleratorActive; private boolean mDragAcceleratorActive; private boolean mHaventMovedEnoughToStartDrag; 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() { SelectionModifierCursorController() { resetTouchOffsets(); resetTouchOffsets(); Loading Loading @@ -4473,6 +4477,7 @@ public class Editor { // Start location of selection. // Start location of selection. mStartOffset = mTextView.getOffsetForPosition(mLastDownPositionX, mStartOffset = mTextView.getOffsetForPosition(mLastDownPositionX, mLastDownPositionY); mLastDownPositionY); mLineSelectionIsOn = mTextView.getLineAtCoordinate(mLastDownPositionY); // Don't show the handles until user has lifted finger. // Don't show the handles until user has lifted finger. hide(); hide(); Loading Loading @@ -4556,17 +4561,35 @@ public class Editor { break; break; } } if (mStartOffset != -1) { if (mStartOffset != -1 && mTextView.getLayout() != null) { if (!mHaventMovedEnoughToStartDrag) { if (!mHaventMovedEnoughToStartDrag) { // Offset the finger by the same vertical offset as the handles. This // improves visibility of the content being selected by shifting float y = eventY; // the finger below the content. 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) final float fingerOffset = (mStartHandle != null) ? mStartHandle.getIdealVerticalOffset() ? mStartHandle.getIdealVerticalOffset() : touchSlop; : touchSlop; int offset = y = eventY - fingerOffset; mTextView.getOffsetForPosition(eventX, 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 startOffset; int offset = mTextView.getOffsetAtCoordinate(currLine, eventX); // Snap to word boundaries. // Snap to word boundaries. if (mStartOffset < offset) { if (mStartOffset < offset) { // Expanding with end handle. // Expanding with end handle. Loading @@ -4577,6 +4600,7 @@ public class Editor { offset = getWordStart(offset); offset = getWordStart(offset); startOffset = getWordEnd(mStartOffset); startOffset = getWordEnd(mStartOffset); } } mLineSelectionIsOn = currLine; Selection.setSelection((Spannable) mTextView.getText(), Selection.setSelection((Spannable) mTextView.getText(), startOffset, offset); startOffset, offset); } } Loading Loading @@ -4613,6 +4637,7 @@ public class Editor { startSelectionActionMode(); startSelectionActionMode(); mDragAcceleratorActive = false; mDragAcceleratorActive = false; mStartOffset = -1; mStartOffset = -1; mSwitchedLines = false; } } break; break; } } Loading Loading @@ -4642,6 +4667,7 @@ public class Editor { mMinTouchOffset = mMaxTouchOffset = -1; mMinTouchOffset = mMaxTouchOffset = -1; mStartOffset = -1; mStartOffset = -1; mDragAcceleratorActive = false; mDragAcceleratorActive = false; mSwitchedLines = false; } } /** /** Loading