From ffd6532bd7baf3fb09cd0ff02496f9f05554561c Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Sun, 6 Nov 2016 18:44:09 -0500 Subject: [PATCH] Bug 1123514 - Correctly calculate text replacement offset; r=esawin Fix a mistake in calculating the correct offset for one of the replacement steps, which caused the IndexOutOfBoundsException. The old code used `oldEnd` for the second text replacement without taking into account the offset change as a result of the first text replacement that was already performed. The new code correctly takes the offset, `delta`, into account. --- .../src/main/java/org/mozilla/gecko/GeckoEditable.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java index f7a017e8d507..8154aabae17e 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java @@ -1220,13 +1220,14 @@ final class GeckoEditable extends JNIObject // Then replace part of the text after the sequence. final int actionStart = indexInText + start; - final int actionEnd = actionStart + action.mEnd - action.mStart; + final int delta = actionStart - action.mStart; + final int actionEnd = delta + action.mEnd; final Spanned currentText = mText.getCurrentText(); final boolean resetSelStart = Selection.getSelectionStart(currentText) == actionEnd; final boolean resetSelEnd = Selection.getSelectionEnd(currentText) == actionEnd; - mText.currentReplace(actionEnd, oldEnd, text.subSequence( + mText.currentReplace(actionEnd, delta + oldEnd, text.subSequence( indexInText + action.mSequence.length(), text.length())); // The replacement above may have shifted our selection, if the selection