Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfa13a77 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

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
parent 96d00ab3
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -105,8 +105,8 @@ public class ExtractEditText extends EditText {
    @Override public boolean onTextContextMenuItem(int id) {
    @Override public boolean onTextContextMenuItem(int id) {
        if (mIME != null && mIME.onExtractTextContextMenuItem(id)) {
        if (mIME != null && mIME.onExtractTextContextMenuItem(id)) {
            // Mode was started on Extracted, needs to be stopped here.
            // Mode was started on Extracted, needs to be stopped here.
            // Cut and paste will change the text, which stops selection mode.
            // Cut will change the text, which stops selection mode.
            if (id == android.R.id.copy) stopTextActionMode();
            if (id == android.R.id.copy || id == android.R.id.paste) stopTextActionMode();
            return true;
            return true;
        }
        }
        return super.onTextContextMenuItem(id);
        return super.onTextContextMenuItem(id);
+20 −9
Original line number Original line Diff line number Diff line
@@ -6347,19 +6347,30 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        if (text.text != null) {
        if (text.text != null) {
            if (content == null) {
            if (content == null) {
                setText(text.text, TextView.BufferType.EDITABLE);
                setText(text.text, TextView.BufferType.EDITABLE);
            } else if (text.partialStartOffset < 0) {
                removeParcelableSpans(content, 0, content.length());
                content.replace(0, content.length(), text.text);
            } else {
            } else {
                int start = 0;
                int end = content.length();

                if (text.partialStartOffset >= 0) {
                    final int N = content.length();
                    final int N = content.length();
                int start = text.partialStartOffset;
                    start = text.partialStartOffset;
                    if (start > N) start = N;
                    if (start > N) start = N;
                int end = text.partialEndOffset;
                    end = text.partialEndOffset;
                    if (end > N) end = N;
                    if (end > N) end = N;
                }

                removeParcelableSpans(content, start, end);
                removeParcelableSpans(content, start, end);
                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);
                    content.replace(start, end, text.text);
                }
                }
            }
            }
        }


        // Now set the selection position...  make sure it is in range, to
        // Now set the selection position...  make sure it is in range, to
        // avoid crashes.  If this is a partial update, it is possible that
        // avoid crashes.  If this is a partial update, it is possible that