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

Commit 65769551 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Enable mouse drag text selection for unfocused TextView."

parents 2f732bf9 88d92da3
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -240,13 +240,20 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme

        boolean handled = Touch.onTouchEvent(widget, buffer, event);

        if (widget.isFocused() && !widget.didTouchFocusSelect()) {
        if (widget.didTouchFocusSelect() && !isMouse) {
            return handled;
        }
        if (action == MotionEvent.ACTION_DOWN) {
            // Capture the mouse pointer down location to ensure selection starts
            // right under the mouse (and is not influenced by cursor location).
            // The code below needs to run for mouse events.
            // For touch events, the code should run only when selection is active.
            if (isMouse || isTouchSelecting(isMouse, buffer)) {
                if (!widget.isFocused()) {
                    if (!widget.requestFocus()) {
                        return handled;
                    }
                }
                int offset = widget.getOffsetForPosition(event.getX(), event.getY());
                buffer.setSpan(LAST_TAP_DOWN, offset, offset, Spannable.SPAN_POINT_POINT);
                // Disallow intercepting of the touch events, so that
@@ -255,8 +262,8 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme
                // mode once the view detected it needed to scroll.
                widget.getParent().requestDisallowInterceptTouchEvent(true);
            }
            } else if (action == MotionEvent.ACTION_MOVE) {

        } else if (widget.isFocused()) {
            if (action == MotionEvent.ACTION_MOVE) {
                // Cursor can be active at any location in the text while mouse pointer can start
                // selection from a totally different location. Use LAST_TAP_DOWN span to ensure
                // text selection will start from mouse pointer location.