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

Commit 720edf95 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Raph Levien
Browse files

Fix: Cursor can be at an invalid offset in EditText.

"getLineEnd(line) - 1" is used as the return value when the
"horiz" is beyond the line end for multiple line text.
In this case, the returned value can point an invalid
offset like the middle point of a surrogate pair.

Bug: 23069901
Change-Id: I1afef7205a15079a42bb0018df73f70fe9ada862
(cherry picked from commit 00ad16d1)
parent d3b2826a
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -1130,13 +1130,18 @@ public abstract class Layout {
     */
     */
    public int getOffsetForHorizontal(int line, float horiz) {
    public int getOffsetForHorizontal(int line, float horiz) {
        // TODO: use Paint.getOffsetForAdvance to avoid binary search
        // TODO: use Paint.getOffsetForAdvance to avoid binary search
        int max = getLineEnd(line) - 1;
        final int lineEndOffset = getLineEnd(line);
        int min = getLineStart(line);
        final int max;
        if (line == getLineCount() - 1) {
            max = lineEndOffset;
        } else {
            max = mPaint.getTextRunCursor(mText, 0, mText.length(),
                    isRtlCharAt(lineEndOffset) ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR,
                    lineEndOffset, Paint.CURSOR_BEFORE);
        }
        final int min = getLineStart(line);
        Directions dirs = getLineDirections(line);
        Directions dirs = getLineDirections(line);


        if (line == getLineCount() - 1)
            max++;

        int best = min;
        int best = min;
        float bestdist = Math.abs(getPrimaryHorizontal(best) - horiz);
        float bestdist = Math.abs(getPrimaryHorizontal(best) - horiz);