From 20900a788f8b946210b2875013b9442aa09041c3 Mon Sep 17 00:00:00 2001 From: Josep del Rio Date: Sat, 4 Mar 2023 15:18:04 +0000 Subject: Exit active mode on Escape key Any key that outputs a Unicode character will allow the user to exit the "active mode" that allows them to compose special characters. However, pressing Escape doesn't do anything, as it will not output any Unicode character. This change adds an extra condition to exit active mode by pressing the Escape key. Bug: 271671045 Test: Flashed phone, confirmed that pressing Escape will cancel the input of an accented character Change-Id: Id3d04758c9fd4cdb65016cca3af30f611b7011e4 --- core/java/android/text/method/QwertyKeyListener.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/java/android/text/method/QwertyKeyListener.java b/core/java/android/text/method/QwertyKeyListener.java index b4a1e8cfe943..c43864d0f215 100644 --- a/core/java/android/text/method/QwertyKeyListener.java +++ b/core/java/android/text/method/QwertyKeyListener.java @@ -360,6 +360,15 @@ public class QwertyKeyListener extends BaseKeyListener { return super.onKeyDown(view, content, keyCode, event); } + return true; + } + } else if (keyCode == KeyEvent.KEYCODE_ESCAPE && event.hasNoModifiers()) { + // If user is in the process of composing with a dead key, and + // presses Escape, cancel it. We need special handling because + // the Escape key will not produce a Unicode character + if (activeStart == selStart && activeEnd == selEnd) { + Selection.setSelection(content, selEnd); + content.removeSpan(TextKeyListener.ACTIVE); return true; } } -- cgit v1.2.3-59-g8ed1b