diff --git a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java index 0422baad3..0ae1d83e3 100644 --- a/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/org/futo/inputmethod/latin/inputlogic/InputLogic.java @@ -1502,12 +1502,12 @@ public final class InputLogic { } } - private void ensureSuggestionStripCompleted(final SettingsValues settingsValues, + private boolean ensureSuggestionStripCompleted(final SettingsValues settingsValues, final String separator, final LatinIMELegacy.UIHandler handler) { LanguageModelFacilitator facilitator = handler.getLanguageModelFacilitator(); if(!facilitator.shouldPassThroughToLegacy()) { if(facilitator.hasPendingUpdate()) { - facilitator.blockUntilComplete(); + return facilitator.blockUntilComplete(); } } else { if (handler.hasPendingUpdateSuggestions()) { @@ -1523,6 +1523,8 @@ public final class InputLogic { performUpdateSuggestionStripSync(settingsValues, SuggestedWords.INPUT_STYLE_TYPING); } } + + return true; } public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, @@ -2177,7 +2179,8 @@ public final class InputLogic { private void commitCurrentAutoCorrection(final SettingsValues settingsValues, final String separator, final LatinIMELegacy.UIHandler handler) { // Complete any pending suggestions query first - ensureSuggestionStripCompleted(settingsValues, separator, handler); + if(!ensureSuggestionStripCompleted(settingsValues, separator, handler)) return; + final SuggestedWordInfo autoCorrectionOrNull = mWordComposer.getAutoCorrectionOrNull(); final String typedWord = mWordComposer.getTypedWord(); final String stringToCommit = (autoCorrectionOrNull != null) diff --git a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt index 84361499e..5ebc8fd8a 100644 --- a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt +++ b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt @@ -136,10 +136,10 @@ public class LanguageModelFacilitator( private var numConsecutiveTimeouts = 0 private var transformerDisabled = false - public fun blockUntilComplete() { + public fun blockUntilComplete(): Boolean { runBlocking { try { - withTimeout(1000L) { + withTimeout(700L) { computationSemaphore.acquire() computationSemaphore.release() try { @@ -150,14 +150,16 @@ public class LanguageModelFacilitator( } numConsecutiveTimeouts = 0 } catch(e: TimeoutCancellationException) { - Log.d("LanguageModelFacilitator", "Failed to complete prediction within 1000ms!") + Log.d("LanguageModelFacilitator", "Failed to complete prediction within the time!") numConsecutiveTimeouts += 1 if(numConsecutiveTimeouts > 5) { transformerDisabled = true Log.w("LanguageModelFacilitator", "Temporarily disabling transformer due to continuous timeouts") } + return@runBlocking false } } + return true } private fun getEmojiCandidate(word: String): SuggestedWordInfo? { @@ -232,6 +234,8 @@ public class LanguageModelFacilitator( computationSemaphore.acquire() + inputLogic.mWordComposer.setAutoCorrection(null) + try { var transformerWeight = context.getSetting(BinaryDictTransformerWeightSetting)