From 73c889a9ab204b8ddbf4fa9bec25d32808df782e Mon Sep 17 00:00:00 2001 From: khaykov Date: Wed, 11 Oct 2023 13:28:05 -0500 Subject: [PATCH] Disabling auto-correct only when keyboard changes. --- .../main/kotlin/org/wordpress/aztec/AztecText.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt index 8d980fdcb..a125de6ef 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt @@ -239,6 +239,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown private var bypassObservationQueue: Boolean = false private var bypassMediaDeletedListener: Boolean = false private var bypassCrashPreventerInputFilter: Boolean = false + private var overrideSamsungPredictiveBehavior: Boolean = false var initialEditorContentParsedSHA256: ByteArray = ByteArray(0) @@ -673,7 +674,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown } override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection { - return requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler() + val inputConnection = requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler() + + if (shouldOverridePredictiveTextBehavior()) { + AppLog.d(AppLog.T.EDITOR, "Disabling autocorrect on Samsung device with Samsung Keyboard with API 33") + outAttrs.inputType = outAttrs.inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS + } + + return inputConnection } private fun InputConnection.wrapWithBackSpaceHandler(): InputConnection { @@ -699,7 +707,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown private fun shouldOverridePredictiveTextBehavior(): Boolean { val currentKeyboard = Settings.Secure.getString(context.contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD) return Build.MANUFACTURER.lowercase(Locale.US) == "samsung" && Build.VERSION.SDK_INT >= 33 && - (currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard")) + (currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard")) && overrideSamsungPredictiveBehavior } // Setup the keyListener(s) for Backspace and Enter key. @@ -1776,9 +1784,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown // Grammarly implementation is often messing spans and cursor position, as described here: // https://github.com/wordpress-mobile/AztecEditor-Android/issues/1023 fun enableSamsungPredictiveBehaviorOverride() { - if(shouldOverridePredictiveTextBehavior()){ - inputType = inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS - } + overrideSamsungPredictiveBehavior = true } fun isMediaDeletedListenerDisabled(): Boolean {