diff --git a/core/java/android/text/method/QwertyKeyListener.java b/core/java/android/text/method/QwertyKeyListener.java index c5261f32e3610..98316ae58da60 100644 --- a/core/java/android/text/method/QwertyKeyListener.java +++ b/core/java/android/text/method/QwertyKeyListener.java @@ -180,6 +180,7 @@ public class QwertyKeyListener extends BaseKeyListener { if (composed != 0) { i = composed; replace = true; + dead = false; } } diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java index 2cb724f31b13d..9e5f25a11a63d 100644 --- a/core/java/android/view/KeyCharacterMap.java +++ b/core/java/android/view/KeyCharacterMap.java @@ -180,6 +180,8 @@ public class KeyCharacterMap implements Parcelable { private static final int ACCENT_CIRCUMFLEX_LEGACY = '^'; private static final int ACCENT_TILDE_LEGACY = '~'; + private static final int CHAR_SPACE = ' '; + /** * Maps Unicode combining diacritical to display-form dead key. */ @@ -473,14 +475,23 @@ public class KeyCharacterMap implements Parcelable { } /** - * Get the character that is produced by putting accent on the character c. + * Get the character that is produced by combining the dead key producing accent + * with the key producing character c. * For example, getDeadChar('`', 'e') returns è. + * getDeadChar('^', ' ') returns '^' and getDeadChar('^', '^') returns '^'. * * @param accent The accent character. eg. '`' * @param c The basic character. * @return The combined character, or 0 if the characters cannot be combined. */ public static int getDeadChar(int accent, int c) { + if (c == accent || CHAR_SPACE == c) { + // The same dead character typed twice or a dead character followed by a + // space should both produce the non-combining version of the combining char. + // In this case we don't even need to compute the combining character. + return accent; + } + int combining = sAccentToCombining.get(accent); if (combining == 0) { return 0; @@ -495,7 +506,8 @@ public class KeyCharacterMap implements Parcelable { sDeadKeyBuilder.append((char)c); sDeadKeyBuilder.append((char)combining); String result = Normalizer.normalize(sDeadKeyBuilder, Normalizer.Form.NFC); - combined = result.length() == 1 ? result.charAt(0) : 0; + combined = result.codePointCount(0, result.length()) == 1 + ? result.codePointAt(0) : 0; sDeadKeyCache.put(combination, combined); } }