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

Commit 1f2c6dea authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix crash when modifying Selection" into pi-dev

parents 219e1396 4e51877f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ public class Selection {
     * Remove the selection or cursor, if any, from the text.
     */
    public static final void removeSelection(Spannable text) {
        text.removeSpan(SELECTION_START);
        text.removeSpan(SELECTION_START, Spanned.SPAN_INTERMEDIATE);
        text.removeSpan(SELECTION_END);
        removeMemory(text);
    }
+13 −0
Original line number Diff line number Diff line
@@ -45,6 +45,19 @@ extends Spanned
     */
    public void removeSpan(Object what);

    /**
     * Remove the specified object from the range of text to which it
     * was attached, if any.  It is OK to remove an object that was never
     * attached in the first place.
     *
     * See {@link Spanned} for an explanation of what the flags mean.
     *
     * @hide
     */
    default void removeSpan(Object what, int flags) {
        removeSpan(what);
    }

    /**
     * Factory used by TextView to create new {@link Spannable Spannables}. You can subclass
     * it to provide something other than {@link SpannableString}.
+15 −4
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
                    // The following condition indicates that the span would become empty
                    (textIsRemoved || mSpanStarts[i] > start || mSpanEnds[i] < mGapStart)) {
                mIndexOfSpan.remove(mSpans[i]);
                removeSpan(i);
                removeSpan(i, 0 /* flags */);
                return true;
            }
            return resolveGap(mSpanStarts[i]) <= end && (i & 1) != 0 &&
@@ -472,7 +472,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
    }

    // Note: caller is responsible for removing the mIndexOfSpan entry.
    private void removeSpan(int i) {
    private void removeSpan(int i, int flags) {
        Object object = mSpans[i];

        int start = mSpanStarts[i];
@@ -496,8 +496,10 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
        // Invariants must be restored before sending span removed notifications.
        restoreInvariants();

        if ((flags & Spanned.SPAN_INTERMEDIATE) == 0) {
            sendSpanRemoved(object, start, end);
        }
    }

    // Documentation from interface
    public SpannableStringBuilder replace(int start, int end, CharSequence tb) {
@@ -782,10 +784,19 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
     * Remove the specified markup object from the buffer.
     */
    public void removeSpan(Object what) {
        removeSpan(what, 0 /* flags */);
    }

    /**
     * Remove the specified markup object from the buffer.
     *
     * @hide
     */
    public void removeSpan(Object what, int flags) {
        if (mIndexOfSpan == null) return;
        Integer i = mIndexOfSpan.remove(what);
        if (i != null) {
            removeSpan(i.intValue());
            removeSpan(i.intValue(), flags);
        }
    }

+11 −2
Original line number Diff line number Diff line
@@ -249,6 +249,13 @@ import java.lang.reflect.Array;
    }

    /* package */ void removeSpan(Object what) {
        removeSpan(what, 0 /* flags */);
    }

    /**
     * @hide
     */
    public void removeSpan(Object what, int flags) {
        int count = mSpanCount;
        Object[] spans = mSpans;
        int[] data = mSpanData;
@@ -266,7 +273,9 @@ import java.lang.reflect.Array;

                mSpanCount--;

                if ((flags & Spanned.SPAN_INTERMEDIATE) == 0) {
                    sendSpanRemoved(what, ostart, oend);
                }
                return;
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -522,7 +522,7 @@ public class BaseInputConnection implements InputConnection {
            b = tmp;
        }

        if (a == b) return null;
        if (a == b || a < 0) return null;

        if ((flags&GET_TEXT_WITH_STYLES) != 0) {
            return content.subSequence(a, b);
Loading