@@ -173,11 +173,6 @@ public boolean hasSlowInputConnection() {
173173
174174 public void onStartInput () {
175175 mLastSlowInputConnectionTime = -SLOW_INPUTCONNECTION_PERSIST_MS ;
176- mIC = mParent .getCurrentInputConnection ();
177- }
178-
179- public void onFinishInput () {
180- mIC = null ;
181176 }
182177
183178 private void checkConsistencyForDebug () {
@@ -379,11 +374,13 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
379374 if (DebugFlags .DEBUG_ENABLED )
380375 Log .d (TAG , "committing " + text .length () + " characters" );
381376 mCommittedTextBeforeComposingText .append (text );
382- if (mExpectedSelStart == INVALID_CURSOR_POSITION ) {
383- mExpectedSelStart = text .length ();
384- } else {
385- mExpectedSelStart += text .length () - mComposingText .length ();
386- }
377+ // TODO: the following is exceedingly error-prone. Right now when the cursor is
378+ // in the
379+ // middle of the composing word mComposingText only holds the part of the
380+ // composing text
381+ // that is before the cursor, so this actually works, but it's terribly
382+ // confusing. Fix this.
383+ mExpectedSelStart += text .length () - mComposingText .length ();
387384 mExpectedSelEnd = mExpectedSelStart ;
388385 mComposingText .setLength (0 );
389386 if (isConnected ()) {
@@ -395,6 +392,10 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
395392 final int spanStart = mTempObjectForCommitText .getSpanStart (span );
396393 final int spanEnd = mTempObjectForCommitText .getSpanEnd (span );
397394 final int spanFlags = mTempObjectForCommitText .getSpanFlags (span );
395+ // We have to adjust the end of the span to include an additional character.
396+ // This is to avoid splitting a unicode surrogate pair.
397+ // See helium314.keyboard.latin.common.Constants.UnicodeSurrogate
398+ // See https://b.corp.google.com/issues/19255233
398399 if (0 < spanEnd && spanEnd < mTempObjectForCommitText .length ()) {
399400 final char spanEndChar = mTempObjectForCommitText .charAt (spanEnd - 1 );
400401 final char nextChar = mTempObjectForCommitText .charAt (spanEnd );
@@ -404,8 +405,7 @@ public void commitText(final CharSequence text, final int newCursorPosition) {
404405 }
405406 }
406407 }
407- final CharSequence textToCommit = spans .length > 0 ? mTempObjectForCommitText : text .toString ();
408- mIC .commitText (textToCommit , newCursorPosition );
408+ mIC .commitText (mTempObjectForCommitText , newCursorPosition );
409409 }
410410 }
411411
@@ -867,11 +867,7 @@ public boolean setComposingText(final CharSequence text, final int newCursorPosi
867867 checkBatchEdit ();
868868 if (DEBUG_PREVIOUS_TEXT )
869869 checkConsistencyForDebug ();
870- if (mExpectedSelStart == INVALID_CURSOR_POSITION ) {
871- mExpectedSelStart = text .length ();
872- } else {
873- mExpectedSelStart += text .length () - mComposingText .length ();
874- }
870+ mExpectedSelStart += text .length () - mComposingText .length ();
875871 mExpectedSelEnd = mExpectedSelStart ;
876872 mComposingText .setLength (0 );
877873 mComposingText .append (text );
0 commit comments