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

Commit 330e263c authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Fix for IndexOutOfBounds in text pasting.

Made paste safe even in case of replace problems due to filters.

Bug 3042016

Change-Id: I9be34fa41fa6117502bbd959f91c562f28fb4237
parent 930d6c3c
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -7485,16 +7485,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                    if (Character.isSpaceChar(paste.charAt(0))) {
                        if (min > 0 && Character.isSpaceChar(mTransformed.charAt(min - 1))) {
                            // Two spaces at beginning of paste: remove one
                            final int originalLength = mText.length();
                            ((Editable) mText).replace(min - 1, min, "");
                            min = min - 1;
                            max = max - 1;
                            // Due to filters, there is no garantee that exactly one character was
                            // removed. Count instead.
                            final int delta = mText.length() - originalLength;
                            min += delta;
                            max += delta;
                        }
                    } else {
                        if (min > 0 && !Character.isSpaceChar(mTransformed.charAt(min - 1))) {
                            // No space at beginning of paste: add one
                            final int originalLength = mText.length();
                            ((Editable) mText).replace(min, min, " ");
                            min = min + 1;
                            max = max + 1;
                            // Taking possible filters into account as above.
                            final int delta = mText.length() - originalLength;
                            min += delta;
                            max += delta;
                        }
                    }