From bb6a62c2be16bf99b2e8b9a4aa15b8dc267ad3fc Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 31 Mar 2015 21:59:30 +0900 Subject: [PATCH] Fix unexpected selection cancellation It turned out that text selection is unexpectedly cancelled by InsertionPointController if it is visible. The InsertPointController is not necessary if there is a selection, so just hiding before performing set selection fixes this issue. Bug: 19946192 Change-Id: I2afce1789d772a8d2ea368643cc7533561ee2bf0 --- core/java/android/widget/Editor.java | 2 +- core/java/android/widget/TextView.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 6e2483735a115..7f8f5abf45283 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -557,7 +557,7 @@ public class Editor { } } - private void hideInsertionPointCursorController() { + void hideInsertionPointCursorController() { if (mInsertionPointCursorController != null) { mInsertionPointCursorController.hide(); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 718ef932ae9a3..863b30c1c080c 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9037,6 +9037,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } boolean selectAllText() { + // Need to hide insert point cursor controller before settings selection, otherwise insert + // point cursor controller obtains cursor update event and update cursor with cancelling + // selection. + if (mEditor != null) { + mEditor.hideInsertionPointCursorController(); + } final int length = mText.length(); Selection.setSelection((Spannable) mText, 0, length); return length > 0;