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

Commit e6831592 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix the empty selection issue when onCreateActionMode returns false" am: 78abed41

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1980526

Change-Id: I95d9fac032b7503d7f9401405bffdfcb50af3a3c
parents bbd97583 78abed41
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -297,12 +297,12 @@ public final class SelectionActionModeHelper {
        } else {
            mTextClassification = null;
        }
        if (mEditor.startActionModeInternal(actionMode)) {
            final SelectionModifierCursorController controller = mEditor.getSelectionController();
            if (controller != null
                    && (mTextView.isTextSelectable() || mTextView.isTextEditable())) {
                controller.show();
            }
        if (mEditor.startActionModeInternal(actionMode)) {
            if (result != null) {
                switch (actionMode) {
                    case Editor.TextActionMode.SELECTION:
+36 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.widget;

import static android.widget.espresso.CustomViewActions.longPressAtRelativeCoordinates;
import static android.widget.espresso.DragHandleUtils.assertNoSelectionHandles;
import static android.widget.espresso.DragHandleUtils.onHandleView;
import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarContainsItem;
import static android.widget.espresso.FloatingToolbarEspressoUtils.assertFloatingToolbarDoesNotContainItem;
@@ -425,6 +426,41 @@ public class TextViewActivityTest {
        assertEquals(latestItem[0], clickedItem[0]);
    }

    @Test
    public void testSelectionOnCreateActionModeReturnsFalse() throws Throwable {
        final String text = "hello world";
        mActivityRule.runOnUiThread(() -> {
            final TextView textView = mActivity.findViewById(R.id.textview);
            textView.setText(text);
            textView.setCustomSelectionActionModeCallback(
                    new ActionMode.Callback() {
                        @Override
                        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                            return false;
                        }

                        @Override
                        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                            return false;
                        }

                        @Override
                        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                            return false;
                        }


                        @Override
                        public void onDestroyActionMode(ActionMode mode) {
                        }
                    });
        });
        mInstrumentation.waitForIdleSync();
        onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf("d")));
        mInstrumentation.waitForIdleSync();
        assertNoSelectionHandles();
    }

    @Test
    public void testSelectionRemovedWhenNonselectableTextLosesFocus() throws Throwable {
        final TextLinks.TextLink textLink = addLinkifiedTextToTextView(R.id.nonselectable_textview);