Merge "Revert to previous text selection behavior" into froyo

This commit is contained in:
Kenny Root
2010-04-05 14:55:10 -07:00
committed by Android (Google) Code Review

View File

@@ -252,7 +252,6 @@ implements MovementMethod
int offset = getOffset(x, y, widget); int offset = getOffset(x, y, widget);
if (cap) { if (cap) {
buffer.setSpan(LAST_TAP_DOWN, offset, offset, buffer.setSpan(LAST_TAP_DOWN, offset, offset,
Spannable.SPAN_POINT_POINT); Spannable.SPAN_POINT_POINT);
@@ -286,13 +285,13 @@ implements MovementMethod
Spannable.SPAN_INCLUSIVE_INCLUSIVE); Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} }
} }
} else if (event.getAction() == MotionEvent.ACTION_MOVE ) { } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
boolean cap = (MetaKeyKeyListener.getMetaState(buffer, boolean cap = (MetaKeyKeyListener.getMetaState(buffer,
KeyEvent.META_SHIFT_ON) == 1) || KeyEvent.META_SHIFT_ON) == 1) ||
(MetaKeyKeyListener.getMetaState(buffer, (MetaKeyKeyListener.getMetaState(buffer,
MetaKeyKeyListener.META_SELECTING) != 0); MetaKeyKeyListener.META_SELECTING) != 0);
if (cap & handled) { if (cap && handled) {
// Before selecting, make sure we've moved out of the "slop". // Before selecting, make sure we've moved out of the "slop".
// handled will be true, if we're in select mode AND we're // handled will be true, if we're in select mode AND we're
// OUT of the slop // OUT of the slop
@@ -308,28 +307,35 @@ implements MovementMethod
int y = (int) event.getY(); int y = (int) event.getY();
int offset = getOffset(x, y, widget); int offset = getOffset(x, y, widget);
// Get the last down touch position (the position at which the final OnePointFiveTapState[] tap = buffer.getSpans(0, buffer.length(),
// user started the selection) OnePointFiveTapState.class);
int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
// Compute the selection boundaries if (tap.length > 0 && tap[0].active) {
int spanstart; // Get the last down touch position (the position at which the
int spanend; // user started the selection)
if (offset >= lastDownOffset) { int lastDownOffset = buffer.getSpanStart(LAST_TAP_DOWN);
// Expand from word start of the original tap to new word
// end, since we are selecting "forwards" // Compute the selection boundaries
spanstart = findWordStart(buffer, lastDownOffset); int spanstart;
spanend = findWordEnd(buffer, offset); int spanend;
if (offset >= lastDownOffset) {
// Expand from word start of the original tap to new word
// end, since we are selecting "forwards"
spanstart = findWordStart(buffer, lastDownOffset);
spanend = findWordEnd(buffer, offset);
} else {
// Expand to from new word start to word end of the original
// tap since we are selecting "backwards".
// The spanend will always need to be associated with the touch
// up position, so that refining the selection with the
// trackball will work as expected.
spanstart = findWordEnd(buffer, lastDownOffset);
spanend = findWordStart(buffer, offset);
}
Selection.setSelection(buffer, spanstart, spanend);
} else { } else {
// Expand to from new word start to word end of the original Selection.extendSelection(buffer, offset);
// tap since we are selecting "backwards".
// The spanend will always need to be associated with the touch
// up position, so that refining the selection with the
// trackball will work as expected.
spanstart = findWordEnd(buffer, lastDownOffset);
spanend = findWordStart(buffer, offset);
} }
Selection.setSelection(buffer, spanstart, spanend);
return true; return true;
} }
} else if (event.getAction() == MotionEvent.ACTION_UP) { } else if (event.getAction() == MotionEvent.ACTION_UP) {
@@ -393,6 +399,8 @@ implements MovementMethod
// If we selecting something with the onepointfivetap-and // If we selecting something with the onepointfivetap-and
// swipe gesture, stop it on finger up. // swipe gesture, stop it on finger up.
MetaKeyKeyListener.stopSelecting(widget, buffer); MetaKeyKeyListener.stopSelecting(widget, buffer);
} else {
Selection.extendSelection(buffer, off);
} }
} else if (doubletap) { } else if (doubletap) {
Selection.setSelection(buffer, Selection.setSelection(buffer,