diff options
| -rw-r--r-- | core/java/android/text/flags/flags.aconfig | 7 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 35 |
2 files changed, 40 insertions, 2 deletions
diff --git a/core/java/android/text/flags/flags.aconfig b/core/java/android/text/flags/flags.aconfig index 6e45fea930d2..f3e0ea780182 100644 --- a/core/java/android/text/flags/flags.aconfig +++ b/core/java/android/text/flags/flags.aconfig @@ -96,3 +96,10 @@ flag { description: "A feature flag for fixing the crash while delete text in insert mode." bug: "314254153" } + +flag { + name: "insert_mode_not_update_selection" + namespace: "text" + description: "Fix that InputService#onUpdateSelection is not called when insert mode gesture is performed." + bug: "300850862" +} diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index e812f858b9fd..90d51402f5b1 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -243,6 +243,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastMath; import com.android.internal.util.Preconditions; +import com.android.text.flags.Flags; import libcore.util.EmptyArray; @@ -539,7 +540,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // System wide time for last cut, copy or text changed action. static long sLastCutCopyOrTextChangedTime; - private ColorStateList mTextColor; private ColorStateList mHintTextColor; private ColorStateList mLinkTextColor; @@ -2857,7 +2857,38 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } if (updateText) { - setText(mText); + if (Flags.insertModeNotUpdateSelection()) { + // Update the transformation text. + if (mTransformation == null) { + mTransformed = mText; + } else { + mTransformed = mTransformation.getTransformation(mText, this); + } + if (mTransformed == null) { + // Should not happen if the transformation method follows the non-null + // postcondition. + mTransformed = ""; + } + final boolean isOffsetMapping = mTransformed instanceof OffsetMapping; + + // If the mText is a Spannable and the new TransformationMethod needs to listen to + // its updates, apply the watcher on it. + if (mTransformation != null && mText instanceof Spannable + && (!mAllowTransformationLengthChange || isOffsetMapping)) { + Spannable sp = (Spannable) mText; + final int priority = isOffsetMapping ? OFFSET_MAPPING_SPAN_PRIORITY : 0; + sp.setSpan(mTransformation, 0, mText.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE + | (priority << Spanned.SPAN_PRIORITY_SHIFT)); + } + if (mLayout != null) { + nullLayouts(); + requestLayout(); + invalidate(); + } + } else { + setText(mText); + } } if (hasPasswordTransformationMethod()) { |