From ed279f8f19098aef31aba43663ab7b3fa43f1999 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Wed, 18 Aug 2010 21:24:35 -0700 Subject: [PATCH] Fix for a bug that prevents text selection on initially empty text edits. Change-Id: I0346b632e7de32b082c0ed7e605873946e3eb554 --- core/java/android/widget/TextView.java | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 051070137c040..25c5b24b89e09 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6584,7 +6584,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener onEndBatchEdit(); hideInsertionPointCursorController(); - stopSelectionActionMode(); + terminateSelectionActionMode(); } startStopMarquee(focused); @@ -6680,7 +6680,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return; } else { // Tapping outside stops selection mode, if any - finishSelectionActionMode(); + stopSelectionActionMode(); } } @@ -6782,9 +6782,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mSelectionModifierCursorController = new SelectionModifierCursorController(); } } else { - mSelectionModifierCursorController = null; // Stop selection mode if the controller becomes unavailable. - finishSelectionActionMode(); + stopSelectionActionMode(); + mSelectionModifierCursorController = null; } } @@ -7029,7 +7029,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private boolean canSelectAll() { - return canSelectText(); + return canSelectText() && mText.length() != 0; } private boolean canSelectText() { @@ -7037,7 +7037,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // If you change this condition, make sure prepareCursorController is called anywhere // the value of this condition might be changed. return (mText instanceof Spannable && - mText.length() != 0 && mMovement != null && mMovement.canSelectArbitrarily()); } @@ -7388,13 +7387,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Same as {@link #finishSelectionActionMode()}, except that there is no cursor controller + * Same as {@link #stopSelectionActionMode()}, except that there is no cursor controller * fade out animation. Needed since the drawable and their alpha values are shared by all * TextViews. Switching from one TextView to another would fade the cursor controllers in the * new one otherwise. */ - private void stopSelectionActionMode() { - finishSelectionActionMode(); + private void terminateSelectionActionMode() { + stopSelectionActionMode(); if (mSelectionModifierCursorController != null) { SelectionModifierCursorController selectionModifierCursorController = (SelectionModifierCursorController) mSelectionModifierCursorController; @@ -7402,7 +7401,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } - private void finishSelectionActionMode() { + private void stopSelectionActionMode() { if (mSelectionActionMode != null) { mSelectionActionMode.finish(); } @@ -7544,7 +7543,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } } - finishSelectionActionMode(); + stopSelectionActionMode(); } return true; @@ -7553,13 +7552,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener clipboard.setPrimaryClip(new ClippedData(null, null, new ClippedData.Item(mTransformed.subSequence(min, max)))); ((Editable) mText).delete(min, max); - finishSelectionActionMode(); + stopSelectionActionMode(); return true; case ID_COPY: clipboard.setPrimaryClip(new ClippedData(null, null, new ClippedData.Item(mTransformed.subSequence(min, max)))); - finishSelectionActionMode(); + stopSelectionActionMode(); return true; } @@ -8058,7 +8057,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private void hideControllers() { hideInsertionPointCursorController(); - finishSelectionActionMode(); + stopSelectionActionMode(); } /**