summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Abodunrinwa Toki <toki@google.com> 2017-05-02 18:44:19 +0100
committer Abodunrinwa Toki <toki@google.com> 2017-05-02 18:44:19 +0100
commit8dd3a744a67bd0ff83629d7023f3cb0634b9a490 (patch)
tree0e55523d3cf7b75cd9953489e94d35ccd783c799
parent90074d1ec8837daef0044137eca8822e4dbc262f (diff)
Support resetting "smart selection" to any word in the selection.
Test: See topic Bug: 34779207 Change-Id: I75a9b991571f750b362047baa13675250e929223
-rw-r--r--core/java/android/widget/Editor.java4
-rw-r--r--core/java/android/widget/SelectionActionModeHelper.java18
2 files changed, 11 insertions, 11 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 481c160369b3..4384427dad35 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -841,7 +841,7 @@ public class Editor {
* Adjusts selection to the word under last touch offset. Return true if the operation was
* successfully performed.
*/
- private boolean selectCurrentWord() {
+ boolean selectCurrentWord() {
if (!mTextView.canSelectText()) {
return false;
}
@@ -2186,7 +2186,7 @@ public class Editor {
}
void onTouchUpEvent(MotionEvent event) {
- if (getSelectionActionModeHelper().resetOriginalSelection(
+ if (getSelectionActionModeHelper().resetSelection(
getTextView().getOffsetForPosition(event.getX(), event.getY()))) {
return;
}
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index beff1b03ef77..450791727fe6 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -98,8 +98,8 @@ final class SelectionActionModeHelper {
}
}
- public boolean resetOriginalSelection(int textIndex) {
- if (mSelectionInfo.resetOriginalSelection(textIndex, mEditor.getTextView().getText())) {
+ public boolean resetSelection(int textIndex) {
+ if (mSelectionInfo.resetSelection(textIndex, mEditor)) {
invalidateActionModeAsync();
return true;
}
@@ -177,9 +177,9 @@ final class SelectionActionModeHelper {
/**
* Holds information about the selection and uses it to decide on whether or not to update
- * the selection when resetOriginalSelection is called.
- * The expected UX here is to allow the user to re-snap the selection back to the original word
- * that was selected with one tap on that word.
+ * the selection when resetSelection is called.
+ * The expected UX here is to allow the user to select a word inside of the "smart selection" on
+ * a single tap.
*/
private static final class SelectionInfo {
@@ -212,14 +212,14 @@ final class SelectionActionModeHelper {
mResetOriginal = false;
}
- public boolean resetOriginalSelection(int textIndex, CharSequence text) {
+ public boolean resetSelection(int textIndex, Editor editor) {
+ final CharSequence text = editor.getTextView().getText();
if (mResetOriginal
- && textIndex >= mOriginalStart && textIndex <= mOriginalEnd
+ && textIndex >= mSelectionStart && textIndex <= mSelectionEnd
&& text instanceof Spannable) {
- Selection.setSelection((Spannable) text, mOriginalStart, mOriginalEnd);
// Only allow a reset once.
mResetOriginal = false;
- return true;
+ return editor.selectCurrentWord();
}
return false;
}