diff --git a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java index 704cf9e5d5..f9e4ec33d7 100644 --- a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java +++ b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java @@ -412,6 +412,7 @@ public final class KMManager { if (Character.isHighSurrogate(charsBackup.charAt(charsBackup.length()-1))) { // Firefox sometimes splits a surrogate pair so move the cursor back ic.commitText("", -1); + Log.d(TAG, "adjust trimming high surrogate pair from charsBackup: " + charsBackup.toString()); charsBackup = ic.getTextBeforeCursor(originalBufferLength, 0); } @@ -2207,7 +2208,7 @@ public final class KMManager { CharSequence charsBefore = ic.getTextBeforeCursor(s.length()*2, 0); int move = adjustCursorPosition(charsBefore, s); if (move > 0) { - Log.d(TAG, "charsBefore: " + charsBefore.toString() + ", s: " + s + ", move: " + move); + Log.d(TAG, "adjusting cursor charsBefore: " + charsBefore.toString() + ", s: " + s + ", move: " + move); ic.commitText("", -move); } } diff --git a/android/KMEA/app/src/test/java/com/tavultesoft/kmea/kmmanager/RestoreCharsTest.java b/android/KMEA/app/src/test/java/com/tavultesoft/kmea/kmmanager/RestoreCharsTest.java index 00fb927ea9..95cde35078 100644 --- a/android/KMEA/app/src/test/java/com/tavultesoft/kmea/kmmanager/RestoreCharsTest.java +++ b/android/KMEA/app/src/test/java/com/tavultesoft/kmea/kmmanager/RestoreCharsTest.java @@ -17,6 +17,7 @@ public class RestoreCharsTest { private final String COMPOSING_DOT_ABOVE = "\u0307"; private final String COMPOSING_CIRCUMFLEX_ACCENT = "\u0302"; + private final String P_COMPOSING_CIRCUMFLEX_ACCENT = "p" + COMPOSING_CIRCUMFLEX_ACCENT; @Test public void test_invalid_input() { @@ -33,12 +34,20 @@ public class RestoreCharsTest { charsToRestore = KMManager.restoreChars(expectedChars, currentContext); Assert.assertEquals("", charsToRestore); - expectedChars = "qwerty"; + expectedChars = WINK; currentContext = "notamatch"; charsToRestore = KMManager.restoreChars(expectedChars, currentContext); Assert.assertEquals("", charsToRestore); } + @Test + public void test_split_surrogate_pair() { + CharSequence expectedChars = "o" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT + WINK + "p"; + CharSequence currentContext = P_COMPOSING_CIRCUMFLEX_ACCENT + "\uD800"; + CharSequence charsToRestore = KMManager.restoreChars(expectedChars, currentContext); + Assert.assertEquals("\uDC3C" + "p", charsToRestore); + } + @Test public void test_chars() { @@ -47,14 +56,14 @@ public class RestoreCharsTest { CharSequence charsToRestore = KMManager.restoreChars(expectedChars, currentContext); Assert.assertEquals(SMILEY + COMPOSING_DOT_ABOVE, charsToRestore); - expectedChars = "qwertyp" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT; + expectedChars = "qwerty" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT; currentContext = "qwertyp"; charsToRestore = KMManager.restoreChars(expectedChars, currentContext); - Assert.assertEquals(COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore); + Assert.assertEquals(COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore); - expectedChars = "qwertyp" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT; + expectedChars = "qwerty" + P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT; currentContext = "qwerty"; charsToRestore = KMManager.restoreChars(expectedChars, currentContext); - Assert.assertEquals("p" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore); + Assert.assertEquals(P_COMPOSING_CIRCUMFLEX_ACCENT + P_COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore); } } \ No newline at end of file