diff options
| author | 2010-08-23 15:14:03 -0700 | |
|---|---|---|
| committer | 2010-08-24 10:18:31 -0700 | |
| commit | 2703a42d16af0e62da1bba02b6c935d98debf936 (patch) | |
| tree | d8c04e0e9080eb2e06d8ddd7f7dd77707dd4dcc1 | |
| parent | b6d71351c074d5c0bc13a91544d776f1524eaabd (diff) | |
When an EditText gains focus by tapping, move the insertion point where tapped.
The previous behavior was to move cursor at the end of the first line,
which feels weird.
Change-Id: I5a72f9871ed79ee2c521698ea642ba126537f4f9
| -rw-r--r-- | core/java/android/text/method/ArrowKeyMovementMethod.java | 20 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 10 |
2 files changed, 10 insertions, 20 deletions
diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java index baaf39dcd03b..3fe14f9b0943 100644 --- a/core/java/android/text/method/ArrowKeyMovementMethod.java +++ b/core/java/android/text/method/ArrowKeyMovementMethod.java @@ -319,25 +319,9 @@ public class ArrowKeyMovementMethod implements MovementMethod { public void onTakeFocus(TextView view, Spannable text, int dir) { if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) { - Layout layout = view.getLayout(); - - if (layout == null) { - /* - * This shouldn't be null, but do something sensible if it is. - */ + if (view.getLayout() == null) { + // This shouldn't be null, but do something sensible if it is. Selection.setSelection(text, text.length()); - } else { - /* - * Put the cursor at the end of the first line, which is - * either the last offset if there is only one line, or the - * offset before the first character of the second line - * if there is more than one line. - */ - if (layout.getLineCount() == 1) { - Selection.setSelection(text, text.length()); - } else { - Selection.setSelection(text, layout.getLineStart(1) - 1); - } } } else { Selection.setSelection(text, text.length()); diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 054bfafeb81c..28234bfe9d1c 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6469,6 +6469,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) { boolean selMoved = mSelectionMoved; + final int touchOffset = + ((SelectionModifierCursorController) mSelectionModifierCursorController). + getMinTouchOffset(); + Selection.setSelection((Spannable) mText, touchOffset); + if (mMovement != null) { mMovement.onTakeFocus(this, (Spannable) mText, direction); } @@ -6680,13 +6685,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (isTextEditable()) { if (action == MotionEvent.ACTION_UP && isFocused() && !mScrolled) { InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); final int newSelStart = getSelectionStart(); final int newSelEnd = getSelectionEnd(); CommitSelectionReceiver csr = null; - if (newSelStart != oldSelStart || newSelEnd != oldSelEnd) { + if (newSelStart != oldSelStart || newSelEnd != oldSelEnd || + didTouchFocusSelect()) { csr = new CommitSelectionReceiver(oldSelStart, oldSelEnd, newSelStart, newSelEnd); } |