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

Commit 5c5c0346 authored by Viktor Yakovel's avatar Viktor Yakovel Committed by Steve Kondik
Browse files

Fix incorrect calculation of start and end indices of changed text

- The problem is taht the calculation of indices does not take the
  difference in original and modified text lengths into account.
- If reportExtractedText() is called from the onDraw() function,
  mInputMethodState is not reset.

The error can occur when the user is editing formatted text using a full screen editor.
One example of formatted text is phone numbers (e.g. dashes are added to North American
numbers by the PhoneNumberFormattingTextWatcher class).
If the two first digits are removed from the number 555-666-777, the new number becomes 566--777.
This is due incorrect calculation of start and end indices of the changed text. The error is in
the TextView class and the problem is that the calculation does not take the difference in original
and modified text lengths into account.

Change-Id: If12d0f571873a6f1874102377432affb64ee21e8
parent 84a478f4
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -4645,6 +4645,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    partialStartOffset = 0;
                    partialEndOffset = N;
                } else {
                    // Now use the delta to determine the actual amount of text
                    // we need.
                    partialEndOffset += delta;
                    // Adjust offsets to ensure we contain full spans.
                    if (content instanceof Spanned) {
                        Spanned spanned = (Spanned)content;
@@ -4660,10 +4663,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                        }
                    }
                    outText.partialStartOffset = partialStartOffset;
                    outText.partialEndOffset = partialEndOffset;
                    // Now use the delta to determine the actual amount of text
                    // we need.
                    partialEndOffset += delta;
                    outText.partialEndOffset = partialEndOffset - delta;

                    if (partialStartOffset > N) {
                        partialStartOffset = N;
                    } else if (partialStartOffset < 0) {
@@ -4727,6 +4728,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                                    + ": " + ims.mTmpExtracted.text);
                            imm.updateExtractedText(this, req.token,
                                    mInputMethodState.mTmpExtracted);
                            ims.mChangedStart = EXTRACT_UNKNOWN;
                            ims.mChangedEnd = EXTRACT_UNKNOWN;
                            ims.mChangedDelta = 0;
                            ims.mContentChanged = false;
                            return true;
                        }
                    }
@@ -6327,8 +6332,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                ims.mChangedStart = start;
                ims.mChangedEnd = start+before;
            } else {
                if (ims.mChangedStart > start) ims.mChangedStart = start;
                if (ims.mChangedEnd < (start+before)) ims.mChangedEnd = start+before;
                ims.mChangedStart = Math.min(ims.mChangedStart, start);
                ims.mChangedEnd = Math.max(ims.mChangedEnd, start + before - ims.mChangedDelta);
            }
            ims.mChangedDelta += after-before;
        }