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

Commit f84a9724 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

Move the "Replace" popup option to the Text Selection ActionMode.

As a first step in unifying the cut/copy/paste ActionMode in Editor
with the paste/replace popup, I'm moving the replace option to
the CAB ActionMode. Paste is already there, so for now all options
are together.

Missing things to address in upcoming CLs:
- Invoke the ActionMode in all cases where the popup shows up now,
ensuring only the options that are currently available show up.
- Get rid of the current popup
- Make the ActionMode a floating toolbar (pending feature completion)
- Define a keyboard shortcut for replace?

Note that since the ActionMode still shows up in the ActionBar and
replace has no icon it now appears as text and takes up lots of
space. This will improve when we can switch to using a floating
toolbar.

Change-Id: Ib6b60bae9b58e4db96b9c4cee556e19d3f1bb466
parent 216ce5d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1724,6 +1724,7 @@ package android {
    field public static final int primary = 16908300; // 0x102000c
    field public static final int progress = 16908301; // 0x102000d
    field public static final int redo = 16908339; // 0x1020033
    field public static final int replaceText = 16908340; // 0x1020034
    field public static final int secondaryProgress = 16908303; // 0x102000f
    field public static final int selectAll = 16908319; // 0x102001f
    field public static final int selectTextMode = 16908333; // 0x102002d
+1 −0
Original line number Diff line number Diff line
@@ -1800,6 +1800,7 @@ package android {
    field public static final int primary = 16908300; // 0x102000c
    field public static final int progress = 16908301; // 0x102000d
    field public static final int redo = 16908339; // 0x1020033
    field public static final int replaceText = 16908340; // 0x1020034
    field public static final int secondaryProgress = 16908303; // 0x102000f
    field public static final int selectAll = 16908319; // 0x102001f
    field public static final int selectTextMode = 16908333; // 0x102002d
+18 −4
Original line number Diff line number Diff line
@@ -2969,6 +2969,12 @@ public class Editor {
                                MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
            }

            if (mTextView.isSuggestionsEnabled() && isCursorInsideSuggestionSpan()) {
                menu.add(0, TextView.ID_REPLACE, 0, com.android.internal.R.string.replace).
                        setShowAsAction(
                                MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
            }

            styledAttributes.recycle();

            if (mCustomSelectionActionModeCallback != null) {
@@ -3000,6 +3006,10 @@ public class Editor {
                 mCustomSelectionActionModeCallback.onActionItemClicked(mode, item)) {
                return true;
            }
            if (item.getItemId() == TextView.ID_REPLACE) {
                onReplace();
                return true;
            }
            return mTextView.onTextContextMenuItem(item.getItemId());
        }

@@ -3028,6 +3038,13 @@ public class Editor {
        }
    }

    private void onReplace() {
        int middle = (mTextView.getSelectionStart() + mTextView.getSelectionEnd()) / 2;
        stopSelectionActionMode();
        Selection.setSelection((Spannable) mTextView.getText(), middle);
        showSuggestions();
    }

    private class ActionPopupWindow extends PinnedPopupWindow implements OnClickListener {
        private static final int POPUP_TEXT_LAYOUT =
                com.android.internal.R.layout.text_edit_action_popup_text;
@@ -3086,10 +3103,7 @@ public class Editor {
                mTextView.onTextContextMenuItem(TextView.ID_PASTE);
                hide();
            } else if (view == mReplaceTextView) {
                int middle = (mTextView.getSelectionStart() + mTextView.getSelectionEnd()) / 2;
                stopSelectionActionMode();
                Selection.setSelection((Spannable) mTextView.getText(), middle);
                showSuggestions();
                onReplace();
            }
        }

+1 −0
Original line number Diff line number Diff line
@@ -8818,6 +8818,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    static final int ID_COPY = android.R.id.copy;
    static final int ID_PASTE = android.R.id.paste;
    static final int ID_PASTE_AS_PLAIN_TEXT = android.R.id.pasteAsPlainText;
    static final int ID_REPLACE = android.R.id.replaceText;

    /**
     * Called when a context menu option for the text view is selected.  Currently
+1 −0
Original line number Diff line number Diff line
@@ -92,4 +92,5 @@
  <item type="id" name="pasteAsPlainText" />
  <item type="id" name="undo" />
  <item type="id" name="redo" />
  <item type="id" name="replaceText" />
</resources>
Loading