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

Commit 09c8a489 authored by Justin Ghan's avatar Justin Ghan
Browse files

Clear TextView focus on escape key press

Bug: 312921137
Test: atest android.widget.cts.TextViewTest
Change-Id: I5fa09ca7edba6fe2321d3bb174cf062057e49414
parent 4d29ed23
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -82,3 +82,10 @@ flag {
  description: "A feature flag that implement inter character justification."
  bug: "283193133"
}

flag {
  name: "escape_clears_focus"
  namespace: "text"
  description: "Feature flag for clearing focus when the escape key is pressed."
  bug: "312921137"
}
+17 −0
Original line number Diff line number Diff line
@@ -9589,6 +9589,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                }
                break;
            case KeyEvent.KEYCODE_ESCAPE:
                if (com.android.text.flags.Flags.escapeClearsFocus() && event.hasNoModifiers()) {
                    if (mEditor != null && mEditor.getTextActionMode() != null) {
                        stopTextActionMode();
                        return KEY_EVENT_HANDLED;
                    }
                    if (hasFocus()) {
                        clearFocus();
                        InputMethodManager imm = getInputMethodManager();
                        if (imm != null) {
                            imm.hideSoftInputFromView(this, 0);
                        }
                        return KEY_EVENT_HANDLED;
                    }
                }
                break;
            case KeyEvent.KEYCODE_CUT:
                if (event.hasNoModifiers() && canCut()) {
                    if (onTextContextMenuItem(ID_CUT)) {