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

Commit c2225b9d authored by Mady Mellor's avatar Mady Mellor
Browse files

Use HandleView's previous offset for text selection handles

HandleView tracks the previous offset of where the handle is at in the text
so it's unnecessary to track it in StartHandleView and EndHandleView again,
this updates them to use the already existing value.

Change-Id: I1a824c9fd9c54ed782e15fa419f23f49abea57a1
parent 9aaaa1eb
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -3342,7 +3342,7 @@ public class Editor {
        // Parent's (TextView) previous position in window
        private int mLastParentX, mLastParentY;
        // Previous text character offset
        private int mPreviousOffset = -1;
        protected int mPreviousOffset = -1;
        // Previous text character offset
        private boolean mPositionHasChanged = true;
        // Minimum touch target size for handles
@@ -3802,8 +3802,6 @@ public class Editor {
    }

    private class SelectionStartHandleView extends HandleView {
        // The previous offset this handle was at.
        private int mPrevOffset;
        // Indicates whether the cursor is making adjustments within a word.
        private boolean mInWord = false;
        // Offset to track difference between touch and word boundary.
@@ -3848,7 +3846,7 @@ public class Editor {
            int end = getWordEnd(offset, true);
            int start = getWordStart(offset);

            if (offset < mPrevOffset) {
            if (offset < mPreviousOffset) {
                // User is increasing the selection.
                if (!mInWord || currLine < mPrevLine) {
                    // We're not in a word, or we're on a different line so we'll expand by
@@ -3857,21 +3855,19 @@ public class Editor {
                    if (offset <= end - offsetToWord || currLine < mPrevLine) {
                        offset = start;
                    } else {
                        offset = mPrevOffset;
                        offset = mPreviousOffset;
                    }
                }
                mPrevOffset = offset;
                mTouchWordOffset = Math.max(trueOffset - offset, 0);
                mInWord = !isStartBoundary(offset);
                positionCursor = true;
            } else if (offset - mTouchWordOffset > mPrevOffset) {
            } else if (offset - mTouchWordOffset > mPreviousOffset) {
                // User is shrinking the selection.
                if (currLine > mPrevLine) {
                    // We're on a different line, so we'll snap to word boundaries.
                    offset = end;
                }
                offset -= mTouchWordOffset;
                mPrevOffset = offset;
                mInWord = !isEndBoundary(offset);
                positionCursor = true;
            }
@@ -3905,8 +3901,6 @@ public class Editor {
    }

    private class SelectionEndHandleView extends HandleView {
        // The previous offset this handle was at.
        private int mPrevOffset;
        // Indicates whether the cursor is making adjustments within a word.
        private boolean mInWord = false;
        // Offset to track difference between touch and word boundary.
@@ -3952,7 +3946,7 @@ public class Editor {
            int end = getWordEnd(offset, true);
            int start = getWordStart(offset);

            if (offset > mPrevOffset) {
            if (offset > mPreviousOffset) {
                // User is increasing the selection.
                if (!mInWord || currLine > mPrevLine) {
                    // We're not in a word, or we're on a different line so we'll expand by
@@ -3961,21 +3955,19 @@ public class Editor {
                    if (offset >= start + midPoint || currLine > mPrevLine) {
                        offset = end;
                    } else {
                        offset = mPrevOffset;
                        offset = mPreviousOffset;
                    }
                }
                mPrevOffset = offset;
                mTouchWordOffset = Math.max(offset - trueOffset, 0);
                mInWord = !isEndBoundary(offset);
                positionCursor = true;
            } else if (offset + mTouchWordOffset < mPrevOffset) {
            } else if (offset + mTouchWordOffset < mPreviousOffset) {
                // User is shrinking the selection.
                if (currLine > mPrevLine) {
                    // We're on a different line, so we'll snap to word boundaries.
                    offset = getWordStart(offset);
                }
                offset += mTouchWordOffset;
                mPrevOffset = offset;
                positionCursor = true;
                mInWord = !isStartBoundary(offset);
            }