improve situation when local state is out of sync with editor

related to / found during tests for 6100186f73
This commit is contained in:
Helium314 2025-01-05 12:08:48 +01:00
parent 6100186f73
commit d08afcd279

View file

@ -653,6 +653,9 @@ public final class RichInputConnection implements PrivateCommandPerformer {
final CharSequence textBeforeCursor = final CharSequence textBeforeCursor =
getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE + (end - start), 0); getTextBeforeCursor(Constants.EDITOR_CONTENTS_CACHE_SIZE + (end - start), 0);
mCommittedTextBeforeComposingText.setLength(0); mCommittedTextBeforeComposingText.setLength(0);
// also clear composing text, otherwise we may append existing text
// this can happen when we're a little out of sync with the editor
mComposingText.setLength(0);
if (!TextUtils.isEmpty(textBeforeCursor)) { if (!TextUtils.isEmpty(textBeforeCursor)) {
// The cursor is not necessarily at the end of the composing text, but we have its // The cursor is not necessarily at the end of the composing text, but we have its
// position in mExpectedSelStart and mExpectedSelEnd. In this case we want the start // position in mExpectedSelStart and mExpectedSelEnd. In this case we want the start
@ -949,6 +952,10 @@ public final class RichInputConnection implements PrivateCommandPerformer {
// If what's after the cursor is a word character, then we're touching a word. // If what's after the cursor is a word character, then we're touching a word.
return true; return true;
} }
if (mComposingText.length() > 0) {
// a composing region should always count as a word
return true;
}
final String textBeforeCursor = mCommittedTextBeforeComposingText.toString(); final String textBeforeCursor = mCommittedTextBeforeComposingText.toString();
int indexOfCodePointInJavaChars = textBeforeCursor.length(); int indexOfCodePointInJavaChars = textBeforeCursor.length();
int consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE int consideredCodePoint = 0 == indexOfCodePointInJavaChars ? Constants.NOT_A_CODE