From d3d1f25c7f6862008f48e947178af405fdad0aca Mon Sep 17 00:00:00 2001 From: Helium314 Date: Mon, 20 Nov 2023 15:27:58 +0100 Subject: [PATCH] get suggestions when typing with cursor in front of composing word, fixes #265 --- .../openboard/inputmethod/latin/WordComposer.java | 4 ++++ .../inputmethod/latin/inputlogic/InputLogic.java | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java index 1de4de041..cc99e8732 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/WordComposer.java @@ -228,6 +228,10 @@ public final class WordComposer { return mCursorPositionWithinWord != mCodePointSize; } + public boolean isCursorInFrontOfComposingWord() { + return mCursorPositionWithinWord == 0; + } + /** * When the cursor is moved by the user, we need to update its position. * If it falls inside the currently composing word, we don't reset the composition, and diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java index 12b98dcd9..a438dff60 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/inputlogic/InputLogic.java @@ -931,13 +931,17 @@ public final class InputLogic { insertAutomaticSpaceIfOptionsAndTextAllow(settingsValues); } - if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { + if (mWordComposer.isCursorInFrontOfComposingWord()) { + // we add something in front of the composing word, this is likely for adding something + // and not for a correction + // keep composing and don't unlearn word in this case + resetEntireInputState(mConnection.getExpectedSelectionStart(), mConnection.getExpectedSelectionEnd(), false); + } else if (mWordComposer.isCursorFrontOrMiddleOfComposingWord()) { // If we are in the middle of a recorrection, we need to commit the recorrection // first so that we can insert the character at the current cursor position. // We also need to unlearn the original word that is now being corrected. unlearnWord(mWordComposer.getTypedWord(), inputTransaction.getMSettingsValues(), Constants.EVENT_BACKSPACE); - resetEntireInputState(mConnection.getExpectedSelectionStart(), - mConnection.getExpectedSelectionEnd(), true /* clearSuggestionStrip */); + resetEntireInputState(mConnection.getExpectedSelectionStart(), mConnection.getExpectedSelectionEnd(), true); isComposingWord = false; } // We want to find out whether to start composing a new word with this character. If so,