diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index b80ddf1af..b1932cd2d 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -1120,7 +1120,7 @@ public class LatinIME extends InputMethodService implements final SettingsValues settingsValues = mSettings.getCurrent(); if (isInputViewShown() && mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, - settingsValues)) { + composingSpanStart, composingSpanEnd, settingsValues)) { mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java index ca34bf6d4..2afc52e0c 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java +++ b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java @@ -1061,10 +1061,17 @@ public final class RichInputConnection implements PrivateCommandPerformer { * @return whether this is a belated expected update or not. */ public boolean isBelatedExpectedUpdate(final int oldSelStart, final int newSelStart, - final int oldSelEnd, final int newSelEnd) { + final int oldSelEnd, final int newSelEnd, final int composingSpanStart, final int composingSpanEnd) { // This update is "belated" if we are expecting it. That is, mExpectedSelStart and // mExpectedSelEnd match the new values that the TextView is updating TO. - if (mExpectedSelStart == newSelStart && mExpectedSelEnd == newSelEnd) return true; + if (mExpectedSelStart == newSelStart && mExpectedSelEnd == newSelEnd) { + if (composingSpanEnd - composingSpanStart < mComposingText.length()) { + // composing span is smaller than expected, maybe changed by the app (see #1141) + // larger composing span is ok, because mComposingText only contains the word up to the cursor + return false; + } + return true; + } // This update is not belated if mExpectedSelStart and mExpectedSelEnd match the old // values, and one of newSelStart or newSelEnd is updated to a different value. In this // case, it is likely that something other than the IME has moved the selection endpoint diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index e0c1da57f..d2bfd2429 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -346,9 +346,9 @@ public final class InputLogic { * @param settingsValues the current values of the settings. * @return whether the cursor has moved as a result of user interaction. */ - public boolean onUpdateSelection(final int oldSelStart, final int oldSelEnd, - final int newSelStart, final int newSelEnd, final SettingsValues settingsValues) { - if (mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart, oldSelEnd, newSelEnd)) { + public boolean onUpdateSelection(final int oldSelStart, final int oldSelEnd, final int newSelStart, + final int newSelEnd, final int composingSpanStart, final int composingSpanEnd, final SettingsValues settingsValues) { + if (mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart, oldSelEnd, newSelEnd, composingSpanStart, composingSpanEnd)) { return false; } // TODO: the following is probably better done in resetEntireInputState().