From c4781e3da0e36845d11655cf157f7c0cff3048fc Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 17 Sep 2023 15:24:36 +0200 Subject: [PATCH] attempt to fix issue in https://github.com/Helium314/openboard/issues/99#issuecomment-1722394199 and some formatting --- .../openboard/inputmethod/latin/LatinIME.java | 21 +++++-------- .../latin/inputlogic/InputLogic.java | 30 ++++++++++--------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java index bcc7d3a7f..dc874d781 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/LatinIME.java @@ -1009,8 +1009,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // span, so we should reset our state unconditionally, even if restarting is true. // We also tell the input logic about the combining rules for the current subtype, so // it can adjust its combiners if needed. - mInputLogic.startInput(mRichImm.getCombiningRulesExtraValueOfCurrentSubtype(), - currentSettingsValues); + mInputLogic.startInput(mRichImm.getCombiningRulesExtraValueOfCurrentSubtype(), currentSettingsValues); resetDictionaryFacilitatorIfNecessary(); @@ -1048,11 +1047,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen currentSettingsValues = mSettings.getCurrent(); if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) { - suggest.setAutoCorrectionThreshold( - currentSettingsValues.mAutoCorrectionThreshold); + suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); } - switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), - getCurrentRecapitalizeState()); + switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); if (needToCallLoadKeyboardLater) { // If we need to call loadKeyboard again later, we need to save its state now. The // later call will be done in #retryResetCaches. @@ -1061,14 +1058,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else if (restarting) { // TODO: Come up with a more comprehensive way to reset the keyboard layout when // a keyboard layout set doesn't get reloaded in this method. - switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(), - getCurrentRecapitalizeState()); + switcher.resetKeyboardStateToAlphabet(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); // In apps like Talk, we come here when the text is sent and the field gets emptied and // we need to re-evaluate the shift state, but not the whole layout which would be // disruptive. // Space state must be updated before calling updateShiftState - switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), - getCurrentRecapitalizeState()); + switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } // This will set the punctuation suggestions if next word suggestion is off; // otherwise it will clear the suggestion strip. @@ -1076,11 +1071,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.cancelUpdateSuggestionStrip(); - mainKeyboardView.setMainDictionaryAvailability( - mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary()); + mainKeyboardView.setMainDictionaryAvailability(mDictionaryFacilitator.hasAtLeastOneInitializedMainDictionary()); mainKeyboardView.setKeyPreviewPopupEnabled(currentSettingsValues.mKeyPreviewPopupOn); - mainKeyboardView.setSlidingKeyInputPreviewEnabled( - currentSettingsValues.mSlidingKeyInputPreviewEnabled); + mainKeyboardView.setSlidingKeyInputPreviewEnabled(currentSettingsValues.mSlidingKeyInputPreviewEnabled); mainKeyboardView.setGestureHandlingEnabledByUser( currentSettingsValues.mGestureInputEnabled, currentSettingsValues.mGestureTrailEnabled, 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 e9fb084dd..b2d71d165 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 @@ -148,8 +148,7 @@ public final class InputLogic { // For messaging apps that offer send button, the IME does not get the opportunity // to capture the last word. This block should capture those uncommitted words. // The timestamp at which it is captured is not accurate but close enough. - StatsUtils.onWordCommitUserTyped( - mWordComposer.getTypedWord(), mWordComposer.isBatchMode()); + StatsUtils.onWordCommitUserTyped(mWordComposer.getTypedWord(), mWordComposer.isBatchMode()); } mWordComposer.restartCombining(combiningSpec); resetComposingState(true /* alsoResetLastComposedWord */); @@ -169,8 +168,7 @@ public final class InputLogic { } if (settingsValues.mShouldShowLxxSuggestionUi) { - mConnection.requestCursorUpdates(true /* enableMonitor */, - true /* requestImmediateCallback */); + mConnection.requestCursorUpdates(true, true); } } @@ -1024,9 +1022,9 @@ public final class InputLogic { // phantom space state when typing decimal numbers, with the drawback of not // setting phantom space state after ending a sentence with a non-word. if (wasComposingWord - && settingsValues.mAutospaceAfterPunctuationEnabled - && settingsValues.isUsuallyFollowedBySpace(codePoint)) { - mSpaceState = SpaceState.PHANTOM; + && settingsValues.mAutospaceAfterPunctuationEnabled + && settingsValues.isUsuallyFollowedBySpace(codePoint)) { + mSpaceState = SpaceState.PHANTOM; } sendKeyCodePoint(settingsValues, codePoint); @@ -1579,11 +1577,12 @@ public final class InputLogic { return; } final int expectedCursorPosition = mConnection.getExpectedSelectionStart(); - if (!mConnection.isCursorTouchingWord(settingsValues.mSpacingAndPunctuations, - true /* checkTextAfter */)) { + if (!mConnection.isCursorTouchingWord(settingsValues.mSpacingAndPunctuations, true /* checkTextAfter */)) { // Show predictions. mWordComposer.setCapitalizedModeAtStartComposingTime(WordComposer.CAPS_MODE_OFF); mLatinIME.mHandler.postUpdateSuggestionStrip(SuggestedWords.INPUT_STYLE_RECORRECTION); + // "unselect" the previous text + mConnection.finishComposingText(); return; } final TextRange range = mConnection.getWordRangeAtCursor( @@ -1596,10 +1595,17 @@ public final class InputLogic { } // If for some strange reason (editor bug or so) we measure the text before the cursor as // longer than what the entire text is supposed to be, the safe thing to do is bail out. - if (range.mHasUrlSpans) return; // If there are links, we don't resume suggestions. Making + if (range.mHasUrlSpans) return; + // If there are links, we don't resume suggestions. Making // edits to a linkified text through batch commands would ruin the URL spans, and unless // we take very complicated steps to preserve the whole link, we can't do things right so // we just do not resume because it's safer. + if (!isResumableWord(settingsValues, range.mWord.toString())) { + mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); + // "unselect" the previous text + mConnection.finishComposingText(); + return; + } final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor(); if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return; final ArrayList suggestions = new ArrayList<>(); @@ -1610,10 +1616,6 @@ public final class InputLogic { SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */, SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */); suggestions.add(typedWordInfo); - if (!isResumableWord(settingsValues, typedWordString)) { - mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); - return; - } int i = 0; for (final SuggestionSpan span : range.getSuggestionSpansAtWord()) { for (final String s : span.getSuggestions()) {