From e57e2e8de5ae046787ee3ae0d1f5b334ca029dda Mon Sep 17 00:00:00 2001 From: Helium314 Date: Wed, 3 Jul 2024 22:30:47 +0200 Subject: [PATCH] dont store cursor position when it can be reloaded before actually using the position should fix #935 also make expected selection start / end private (access still via get methods) --- .../helium314/keyboard/latin/RichInputConnection.java | 4 ++-- .../helium314/keyboard/latin/inputlogic/InputLogic.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java index a5c963436..151e44804 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java +++ b/app/src/main/java/helium314/keyboard/latin/RichInputConnection.java @@ -99,12 +99,12 @@ public final class RichInputConnection implements PrivateCommandPerformer { * It's not really the selection start position: the selection start may not be there yet, and * in some cases, it may never arrive there. */ - public int mExpectedSelStart = INVALID_CURSOR_POSITION; // in chars, not code points + private int mExpectedSelStart = INVALID_CURSOR_POSITION; // in chars, not code points /** * The expected selection end. Only differs from mExpectedSelStart if a non-empty selection is * expected. The same caveats as mExpectedSelStart apply. */ - public int mExpectedSelEnd = INVALID_CURSOR_POSITION; // in chars, not code points + private int mExpectedSelEnd = INVALID_CURSOR_POSITION; // in chars, not code points /** * This contains the committed text immediately preceding the cursor and the composing * text, if any. It is refreshed when the cursor moves by calling upon the TextView. 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 2b5dd3177..c000d1334 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -923,7 +923,7 @@ public final class InputLogic { final CharSequence text = mConnection.textBeforeCursorUntilLastWhitespaceOrDoubleSlash(); final TextRange range = new TextRange(text, 0, text.length(), text.length(), false); isComposingWord = true; - restartSuggestions(range, mConnection.mExpectedSelStart); + restartSuggestions(range); } // TODO: remove isWordConnector() and use isUsuallyFollowedBySpace() instead. // See onStartBatchInput() to see how to do it. @@ -1670,7 +1670,6 @@ public final class InputLogic { mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); return; } - final int expectedCursorPosition = mConnection.getExpectedSelectionStart(); if (!mConnection.isCursorTouchingWord(settingsValues.mSpacingAndPunctuations, true /* checkTextAfter */)) { // Show predictions. mWordComposer.setCapitalizedModeAtStartComposingTime(WordComposer.CAPS_MODE_OFF); @@ -1700,11 +1699,12 @@ public final class InputLogic { mConnection.finishComposingText(); return; } - restartSuggestions(range, expectedCursorPosition); + restartSuggestions(range); } - private void restartSuggestions(final TextRange range, final int expectedCursorPosition) { + private void restartSuggestions(final TextRange range) { final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor(); + final int expectedCursorPosition = mConnection.getExpectedSelectionStart(); if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return; final ArrayList suggestions = new ArrayList<>(); final String typedWordString = range.mWord.toString();