Merge "Other improvements to text cursor movement." into gingerbread

This commit is contained in:
Gilles Debunne
2010-10-08 17:14:45 -07:00
committed by Android (Google) Code Review

View File

@@ -6551,7 +6551,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) { if (!mFrozenWithFocus || (selStart < 0 || selEnd < 0)) {
// If a tap was used to give focus to that view, move cursor at tap position. // If a tap was used to give focus to that view, move cursor at tap position.
// Has to be done before onTakeFocus, which can be overloaded. // Has to be done before onTakeFocus, which can be overloaded.
moveCursorToLastTapPosition(); final int lastTapPosition = getLastTapPosition();
if (lastTapPosition >= 0) {
Selection.setSelection((Spannable) mText, lastTapPosition);
}
if (mMovement != null) { if (mMovement != null) {
mMovement.onTakeFocus(this, (Spannable) mText, direction); mMovement.onTakeFocus(this, (Spannable) mText, direction);
@@ -6610,6 +6613,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} else { } else {
terminateTextSelectionMode(); terminateTextSelectionMode();
} }
if (mSelectionModifierCursorController != null) {
((SelectionModifierCursorController) mSelectionModifierCursorController).resetTouchOffsets();
}
} }
startStopMarquee(focused); startStopMarquee(focused);
@@ -6621,20 +6628,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
super.onFocusChanged(focused, direction, previouslyFocusedRect); super.onFocusChanged(focused, direction, previouslyFocusedRect);
} }
private void moveCursorToLastTapPosition() { private int getLastTapPosition() {
if (mSelectionModifierCursorController != null) { if (mSelectionModifierCursorController != null) {
int mTapToFocusPosition = ((SelectionModifierCursorController) int lastTapPosition = ((SelectionModifierCursorController)
mSelectionModifierCursorController).getMinTouchOffset(); mSelectionModifierCursorController).getMinTouchOffset();
if (mTapToFocusPosition >= 0) { if (lastTapPosition >= 0) {
// Safety check, should not be possible. // Safety check, should not be possible.
if (mTapToFocusPosition > mText.length()) { if (lastTapPosition > mText.length()) {
Log.e(LOG_TAG, "Invalid tap focus position (" + mTapToFocusPosition + " vs " Log.e(LOG_TAG, "Invalid tap focus position (" + lastTapPosition + " vs "
+ mText.length() + ")"); + mText.length() + ")");
mTapToFocusPosition = mText.length(); lastTapPosition = mText.length();
} }
Selection.setSelection((Spannable) mText, mTapToFocusPosition); return lastTapPosition;
} }
} }
return -1;
} }
@Override @Override
@@ -7297,10 +7306,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
private String getWordForDictionary() { private String getWordForDictionary() {
if (!mContextMenuTriggeredByKey) { int seedPosition = mContextMenuTriggeredByKey ? getSelectionStart() : getLastTapPosition();
moveCursorToLastTapPosition(); long wordLimits = getWordLimitsAt(seedPosition);
}
long wordLimits = getWordLimitsAt(getSelectionStart());
if (wordLimits >= 0) { if (wordLimits >= 0) {
int start = extractRangeStartFromLong(wordLimits); int start = extractRangeStartFromLong(wordLimits);
int end = extractRangeEndFromLong(wordLimits); int end = extractRangeEndFromLong(wordLimits);
@@ -8019,7 +8026,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
SelectionModifierCursorController() { SelectionModifierCursorController() {
mStartHandle = new HandleView(this, HandleView.LEFT); mStartHandle = new HandleView(this, HandleView.LEFT);
mEndHandle = new HandleView(this, HandleView.RIGHT); mEndHandle = new HandleView(this, HandleView.RIGHT);
mMinTouchOffset = mMaxTouchOffset = -1; resetTouchOffsets();
} }
public void show() { public void show() {
@@ -8151,6 +8158,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
return mMaxTouchOffset; return mMaxTouchOffset;
} }
public void resetTouchOffsets() {
mMinTouchOffset = mMaxTouchOffset = -1;
}
/** /**
* @return true iff this controller is currently used to move the selection start. * @return true iff this controller is currently used to move the selection start.
*/ */