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

Commit 86d60cde authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Fix crash due to reverse selection.

Selection start can be bigger than selection end and this kind
of selection is generated by mouse selection at least from L MR1.

To fix and support SHARE button for this kind of selection,
getSelectedText need to invert selection start and selection end
when the selection start is bigger than selection end.

Bug: 22065979
Change-Id: Ide4ac41e3f59d256033aca004450712ca0bb0f03
parent d4d802be
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -7562,12 +7562,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    }

    String getSelectedText() {
        if (hasSelection()) {
            return String.valueOf(mText.subSequence(getSelectionStart(), getSelectionEnd()));
        }
        if (!hasSelection()) {
            return null;
        }

        final int start = getSelectionStart();
        final int end = getSelectionEnd();
        return String.valueOf(
                start > end ? mText.subSequence(end, start) : mText.subSequence(start, end));
    }

    /**
     * Sets the properties of this field (lines, horizontally scrolling,
     * transformation method) to be for a single-line input.