diff options
| author | Andrei Stingaceanu <stg@google.com> | 2015-07-08 15:07:59 +0100 |
|---|---|---|
| committer | Andrei Stingaceanu <stg@google.com> | 2015-07-13 11:14:43 +0100 |
| commit | cfa13a77ed8f7fb479fd3556c93586654200f7ea (patch) | |
| tree | 272ec114201630d37a6daa314413c03c799b5567 /core/java/android/widget/TextView.java | |
| parent | 96d00ab359d60197321f06b4feb3d01f3fa03a29 (diff) | |
Fix insertion handle disappearing in extract mode
In extract mode, on every screen touch
TextView#setExtractedText gets called which calls
SpannableStringBuilder#sendTextChanged which in turn stops
the action mode. As a fix, if the text is the same only
copy the spans without replacing everything.
Bug: 22315095
Change-Id: I28da760b3dc11e1cfbaf720e547bd817c5b89d7e
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 42ac599d8979..131ba4674755 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6347,17 +6347,28 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (text.text != null) { if (content == null) { setText(text.text, TextView.BufferType.EDITABLE); - } else if (text.partialStartOffset < 0) { - removeParcelableSpans(content, 0, content.length()); - content.replace(0, content.length(), text.text); } else { - final int N = content.length(); - int start = text.partialStartOffset; - if (start > N) start = N; - int end = text.partialEndOffset; - if (end > N) end = N; + int start = 0; + int end = content.length(); + + if (text.partialStartOffset >= 0) { + final int N = content.length(); + start = text.partialStartOffset; + if (start > N) start = N; + end = text.partialEndOffset; + if (end > N) end = N; + } + removeParcelableSpans(content, start, end); - content.replace(start, end, text.text); + if (TextUtils.equals(content.subSequence(start, end), text.text)) { + if (text.text instanceof Spanned) { + // OK to copy spans only. + TextUtils.copySpansFrom((Spanned) text.text, start, end, + Object.class, content, start); + } + } else { + content.replace(start, end, text.text); + } } } |
