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

Commit 4aca1373 authored by kaiyiz's avatar kaiyiz Committed by Linux Build Service Account
Browse files

MMS: Fix Messaging will force close after tap one item in suggestion list

The span end is larger than string's length, it caused IndexOutOfBounds
exception.

Check the span end to avoid the IndexOutOfBounds exception.

CRs-Fixed: 555378

Change-Id: Iaf1cbe8db8704b3112afb6207982750b650fe5c5
parent 2a5777a3
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2767,14 +2767,22 @@ public class Editor {
                    // way to assign them a valid range after replacement
                    if (suggestionSpansStarts[i] <= spanStart &&
                            suggestionSpansEnds[i] >= spanEnd) {
                        // When the SpansEnd beyond the length of mTextView here should avoid it.
                        int nTextLen = mTextView.getText().length();
                        int spansEnd = suggestionSpansEnds[i] + lengthDifference;
                        int realSpansEnd = spansEnd > nTextLen ? nTextLen : spansEnd;
                        mTextView.setSpan_internal(suggestionSpans[i], suggestionSpansStarts[i],
                                suggestionSpansEnds[i] + lengthDifference, suggestionSpansFlags[i]);
                                realSpansEnd, suggestionSpansFlags[i]);
                    }
                }

                // Move cursor at the end of the replaced word
                final int newCursorPosition = spanEnd + lengthDifference;
                mTextView.setCursorPosition_internal(newCursorPosition, newCursorPosition);
                // When the SpansEnd beyond the length of mTextView here should avoid it.
                int textLen = mTextView.getText().length();
                int realNewCursorPosition = newCursorPosition > textLen ? textLen
                        : newCursorPosition;
                mTextView.setCursorPosition_internal(realNewCursorPosition, realNewCursorPosition);
            }

            hide();