Skip to content

Commit 004b02d

Browse files
author
Gilles Debunne
committed
Touch moves cursor in text refactored
Code was moved back from the movement method to the touch event code in TextView. Change-Id: I7dc0d957554ddce08e810d20e0385f98802ef1a4
1 parent b3ca0fe commit 004b02d

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

core/java/android/text/method/ArrowKeyMovementMethod.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event
280280
if (isSelecting(buffer)) {
281281
buffer.removeSpan(LAST_TAP_DOWN);
282282
Selection.extendSelection(buffer, offset);
283-
} else if (!widget.shouldIgnoreActionUpEvent()) {
284-
Selection.setSelection(buffer, offset);
285283
}
286284

287285
MetaKeyKeyListener.adjustMetaAfterKeypress(buffer);

core/java/android/widget/TextView.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8353,7 +8353,7 @@ public boolean onTouchEvent(MotionEvent event) {
83538353
}
83548354

83558355
final boolean touchIsFinished = (action == MotionEvent.ACTION_UP) &&
8356-
!shouldIgnoreActionUpEvent() && isFocused();
8356+
!mIgnoreActionUpEvent && isFocused();
83578357

83588358
if ((mMovement != null || onCheckIsTextEditor()) && isEnabled()
83598359
&& mText instanceof Spannable && mLayout != null) {
@@ -8377,6 +8377,10 @@ public boolean onTouchEvent(MotionEvent event) {
83778377
}
83788378

83798379
if (touchIsFinished && (isTextEditable() || mTextIsSelectable)) {
8380+
// Move cursor
8381+
final int offset = getOffsetForPosition(event.getX(), event.getY());
8382+
Selection.setSelection((Spannable) mText, offset);
8383+
83808384
// Show the IME, except when selecting in read-only text.
83818385
final InputMethodManager imm = InputMethodManager.peekInstance();
83828386
viewClicked(imm);
@@ -8529,17 +8533,6 @@ public void cancelLongPress() {
85298533
mIgnoreActionUpEvent = true;
85308534
}
85318535

8532-
/**
8533-
* This method is only valid during a touch event.
8534-
*
8535-
* @return true when the ACTION_UP event should be ignored, false otherwise.
8536-
*
8537-
* @hide
8538-
*/
8539-
public boolean shouldIgnoreActionUpEvent() {
8540-
return mIgnoreActionUpEvent;
8541-
}
8542-
85438536
@Override
85448537
public boolean onTrackballEvent(MotionEvent event) {
85458538
if (mMovement != null && mText instanceof Spannable &&
@@ -10147,8 +10140,8 @@ private boolean startSelectionActionMode() {
1014710140

1014810141
boolean willExtract = extractedTextModeWillBeStarted();
1014910142

10150-
// Do not start the action mode when extracted text will show up full screen, thus
10151-
// immediately hiding the newly created action bar, which would be visually distracting.
10143+
// Do not start the action mode when extracted text will show up full screen, which would
10144+
// immediately hide the newly created action bar and would be visually distracting.
1015210145
if (!willExtract) {
1015310146
ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
1015410147
mSelectionActionMode = startActionMode(actionModeCallback);

0 commit comments

Comments
 (0)