mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-18 14:27:43 +00:00
Merge pull request #10873 from keymanapp/fix/android/repeated-char-backspace
fix(android): fixes context-change detection for repeated-char cases
This commit is contained in:
commit
ccbeecf7d0
3 changed files with 14 additions and 3 deletions
|
|
@ -297,12 +297,13 @@ public class KMKeyboardJSHandler {
|
|||
expectedChars = "";
|
||||
}
|
||||
ic.deleteSurroundingText(dn + numPairs, 0);
|
||||
CharSequence newContext = getCharacterSequence(ic, originalBufferLength - 2*dn);
|
||||
// Shorten the retrieved context by exactly as many characters as were just deleted.
|
||||
CharSequence newContext = getCharacterSequence(ic, originalBufferLength - dn - numPairs);
|
||||
|
||||
CharSequence charsToRestore = CharSequenceUtil.restoreChars(expectedChars, newContext);
|
||||
if (charsToRestore.length() > 0) {
|
||||
// Restore expectedChars that Chromium deleted.
|
||||
// Use newCusorPosition 1 so cursor will be after the inserted string
|
||||
// Use newCursorPosition 1 so cursor will be after the inserted string
|
||||
ic.commitText(charsToRestore, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,10 @@ public final class CharSequenceUtil {
|
|||
if (expectedChars.length() != currentContext.length()) {
|
||||
String expectedCharsString = expectedChars.toString();
|
||||
String currentContextString = currentContext.toString();
|
||||
int index = expectedCharsString.indexOf(currentContextString);
|
||||
int index = expectedCharsString.lastIndexOf(currentContextString);
|
||||
if (currentContextString.length() == 0) {
|
||||
index = 0;
|
||||
}
|
||||
if (index > -1) {
|
||||
// subSequence indices are start(inclusive) to end(exclusive)
|
||||
charsToRestore = expectedChars.subSequence(index + currentContextString.length(), expectedChars.length());
|
||||
|
|
|
|||
|
|
@ -151,5 +151,12 @@ public class CharSequenceUtilTest {
|
|||
Assert.assertEquals("p" + COMPOSING_CIRCUMFLEX_ACCENT + "p" + COMPOSING_CIRCUMFLEX_ACCENT, charsToRestore);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_repeated_char_backspace() {
|
||||
CharSequence currentContext = "----------------";
|
||||
CharSequence expectedChars = "-----------------";
|
||||
CharSequence charsToRestore = CharSequenceUtil.restoreChars(expectedChars, currentContext);
|
||||
Assert.assertEquals("", charsToRestore);
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue