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

Commit dbe2c293 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Fix: Drag handle jumps between bidi boundaries.

mHotspotX and mHorizontalGravity was updated even when the
handle is dragging. As a result, updatePosition() can be
called with the adjusted coordinate for the updated text
direction.

Bug: 21131463
Change-Id: Ie3c2215a0d978db655d55693ee484f04ce5b35fa
parent 99fbb56a
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -3501,13 +3501,24 @@ public class Editor {
        }

        protected void updateDrawable() {
            if (mIsDragging) {
                // Don't update drawable during dragging.
                return;
            }
            final int offset = getCurrentCursorOffset();
            final boolean isRtlCharAtOffset = mTextView.getLayout().isRtlCharAt(offset);
            final Drawable oldDrawable = mDrawable;
            mDrawable = isRtlCharAtOffset ? mDrawableRtl : mDrawableLtr;
            mHotspotX = getHotspotX(mDrawable, isRtlCharAtOffset);
            mHorizontalGravity = getHorizontalGravity(isRtlCharAtOffset);
            if (oldDrawable != mDrawable) {
            final Layout layout = mTextView.getLayout();
            if (layout != null && oldDrawable != mDrawable && isShowing()) {
                // Update popup window position.
                mPositionX = (int) (layout.getPrimaryHorizontal(offset) - 0.5f - mHotspotX -
                        getHorizontalOffset() + getCursorOffset());
                mPositionX += mTextView.viewportToContentHorizontalOffset();
                mPositionHasChanged = true;
                updatePosition(mLastParentX, mLastParentY, false, false);
                postInvalidate();
            }
        }
@@ -3781,10 +3792,12 @@ public class Editor {
                case MotionEvent.ACTION_UP:
                    filterOnTouchUp();
                    mIsDragging = false;
                    updateDrawable();
                    break;

                case MotionEvent.ACTION_CANCEL:
                    mIsDragging = false;
                    updateDrawable();
                    break;
            }
            return true;