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

Commit 532c8e9b authored by Clara Bayarri's avatar Clara Bayarri Committed by Android (Google) Code Review
Browse files

Merge "Editor: Fire the selection Action Mode when long pressing on an empty space"

parents 78d9de97 29d2b5aa
Loading
Loading
Loading
Loading
+21 −7
Original line number Original line Diff line number Diff line
@@ -309,7 +309,7 @@ public class Editor {
            mTextView.setHasTransientState(false);
            mTextView.setHasTransientState(false);


            // We had an active selection from before, start the selection mode.
            // We had an active selection from before, start the selection mode.
            startSelectionActionMode();
            startSelectionActionModeWithSelection();
        }
        }


        getPositionListener().addSubscriber(mCursorAnchorInfoNotifier, true);
        getPositionListener().addSubscriber(mCursorAnchorInfoNotifier, true);
@@ -976,14 +976,15 @@ public class Editor {
    }
    }


    public boolean performLongClick(boolean handled) {
    public boolean performLongClick(boolean handled) {
        // Long press in empty space moves cursor and shows the Paste affordance if available.
        // Long press in empty space moves cursor and starts the selection action mode.
        if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) &&
        if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) &&
                mInsertionControllerEnabled) {
                mInsertionControllerEnabled) {
            final int offset = mTextView.getOffsetForPosition(mLastDownPositionX,
            final int offset = mTextView.getOffsetForPosition(mLastDownPositionX,
                    mLastDownPositionY);
                    mLastDownPositionY);
            stopSelectionActionMode();
            stopSelectionActionMode();
            Selection.setSelection((Spannable) mTextView.getText(), offset);
            Selection.setSelection((Spannable) mTextView.getText(), offset);
            getInsertionController().showWithActionPopup();
            getInsertionController().show();
            startSelectionActionModeWithoutSelection();
            handled = true;
            handled = true;
        }
        }


@@ -999,14 +1000,14 @@ public class Editor {
                stopSelectionActionMode();
                stopSelectionActionMode();
            } else {
            } else {
                stopSelectionActionMode();
                stopSelectionActionMode();
                startSelectionActionMode();
                startSelectionActionModeWithSelection();
            }
            }
            handled = true;
            handled = true;
        }
        }


        // Start a new selection
        // Start a new selection
        if (!handled) {
        if (!handled) {
            handled = startSelectionActionMode();
            handled = startSelectionActionModeWithSelection();
        }
        }


        return handled;
        return handled;
@@ -1657,7 +1658,20 @@ public class Editor {
    /**
    /**
     * @return true if the selection mode was actually started.
     * @return true if the selection mode was actually started.
     */
     */
    boolean startSelectionActionMode() {
    private boolean startSelectionActionModeWithoutSelection() {
        if (mSelectionActionMode != null) {
            // Selection action mode is already started
            return false;
        }
        ActionMode.Callback actionModeCallback = new SelectionActionModeCallback();
        mSelectionActionMode = mTextView.startActionMode(actionModeCallback);
        return mSelectionActionMode != null;
    }

    /**
     * @return true if the selection mode was actually started.
     */
    boolean startSelectionActionModeWithSelection() {
        if (mSelectionActionMode != null) {
        if (mSelectionActionMode != null) {
            // Selection action mode is already started
            // Selection action mode is already started
            return false;
            return false;
@@ -4203,7 +4217,7 @@ public class Editor {
                            boolean stayedInArea = distanceSquared < doubleTapSlop * doubleTapSlop;
                            boolean stayedInArea = distanceSquared < doubleTapSlop * doubleTapSlop;


                            if (stayedInArea && isPositionOnText(x, y)) {
                            if (stayedInArea && isPositionOnText(x, y)) {
                                startSelectionActionMode();
                                startSelectionActionModeWithSelection();
                                mDiscardNextActionUp = true;
                                mDiscardNextActionUp = true;
                            }
                            }
                        }
                        }
+3 −3
Original line number Original line Diff line number Diff line
@@ -5104,7 +5104,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // - onFocusChanged cannot start it when focus is given to a view with selected text (after
        // - onFocusChanged cannot start it when focus is given to a view with selected text (after
        //   a screen rotation) since layout is not yet initialized at that point.
        //   a screen rotation) since layout is not yet initialized at that point.
        if (mEditor != null && mEditor.mCreatedWithASelection) {
        if (mEditor != null && mEditor.mCreatedWithASelection) {
            mEditor.startSelectionActionMode();
            mEditor.startSelectionActionModeWithSelection();
            mEditor.mCreatedWithASelection = false;
            mEditor.mCreatedWithASelection = false;
        }
        }


@@ -5112,7 +5112,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // ExtractEditText does not call onFocus when it is displayed, and mHasSelectionOnFocus can
        // ExtractEditText does not call onFocus when it is displayed, and mHasSelectionOnFocus can
        // not be set. Do the test here instead.
        // not be set. Do the test here instead.
        if (this instanceof ExtractEditText && hasSelection() && mEditor != null) {
        if (this instanceof ExtractEditText && hasSelection() && mEditor != null) {
            mEditor.startSelectionActionMode();
            mEditor.startSelectionActionModeWithSelection();
        }
        }


        unregisterForPreDraw();
        unregisterForPreDraw();
@@ -8745,7 +8745,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                            Selection.setSelection((Spannable) text, start, end);
                            Selection.setSelection((Spannable) text, start, end);
                            // Make sure selection mode is engaged.
                            // Make sure selection mode is engaged.
                            if (mEditor != null) {
                            if (mEditor != null) {
                                mEditor.startSelectionActionMode();
                                mEditor.startSelectionActionModeWithSelection();
                            }
                            }
                            return true;
                            return true;
                        }
                        }