am 2703a42d: When an EditText gains focus by tapping, move the insertion point where tapped.

Merge commit '2703a42d16af0e62da1bba02b6c935d98debf936' into gingerbread-plus-aosp

* commit '2703a42d16af0e62da1bba02b6c935d98debf936':
  When an EditText gains focus by tapping, move the insertion point where tapped.
This commit is contained in:
Gilles Debunne
2010-08-24 10:30:09 -07:00
committed by Android Git Automerger
2 changed files with 10 additions and 20 deletions

View File

@@ -319,25 +319,9 @@ public class ArrowKeyMovementMethod implements MovementMethod {
public void onTakeFocus(TextView view, Spannable text, int dir) { public void onTakeFocus(TextView view, Spannable text, int dir) {
if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) { if ((dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0) {
Layout layout = view.getLayout(); if (view.getLayout() == null) {
// This shouldn't be null, but do something sensible if it is.
if (layout == null) {
/*
* This shouldn't be null, but do something sensible if it is.
*/
Selection.setSelection(text, text.length()); 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 { } else {
Selection.setSelection(text, text.length()); Selection.setSelection(text, text.length());

View File

@@ -6474,6 +6474,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) { if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
boolean selMoved = mSelectionMoved; boolean selMoved = mSelectionMoved;
final int touchOffset =
((SelectionModifierCursorController) mSelectionModifierCursorController).
getMinTouchOffset();
Selection.setSelection((Spannable) mText, touchOffset);
if (mMovement != null) { if (mMovement != null) {
mMovement.onTakeFocus(this, (Spannable) mText, direction); mMovement.onTakeFocus(this, (Spannable) mText, direction);
} }
@@ -6691,7 +6696,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final int newSelEnd = getSelectionEnd(); final int newSelEnd = getSelectionEnd();
CommitSelectionReceiver csr = null; CommitSelectionReceiver csr = null;
if (newSelStart != oldSelStart || newSelEnd != oldSelEnd) { if (newSelStart != oldSelStart || newSelEnd != oldSelEnd ||
didTouchFocusSelect()) {
csr = new CommitSelectionReceiver(oldSelStart, oldSelEnd, csr = new CommitSelectionReceiver(oldSelStart, oldSelEnd,
newSelStart, newSelEnd); newSelStart, newSelEnd);
} }