Skip to content

Commit 794e1bd

Browse files
committed
Instead of input connection override disable auto-correct.
1 parent 29b449e commit 794e1bd

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import android.os.Parcelable
3636
import android.provider.Settings
3737
import android.text.Editable
3838
import android.text.InputFilter
39+
import android.text.InputType
3940
import android.text.Spannable
4041
import android.text.SpannableStringBuilder
4142
import android.text.Spanned
@@ -238,7 +239,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
238239
private var bypassObservationQueue: Boolean = false
239240
private var bypassMediaDeletedListener: Boolean = false
240241
private var bypassCrashPreventerInputFilter: Boolean = false
241-
private var overrideSamsungPredictiveBehavior: Boolean = false
242242

243243
var initialEditorContentParsedSHA256: ByteArray = ByteArray(0)
244244

@@ -673,13 +673,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
673673
}
674674

675675
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection {
676-
val baseInputConnection = requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler()
677-
return if (shouldOverridePredictiveTextBehavior()) {
678-
AppLog.d(AppLog.T.EDITOR, "Overriding predictive text behavior on Samsung device with Samsung Keyboard with API 33")
679-
SamsungInputConnection(this, baseInputConnection)
680-
} else {
681-
baseInputConnection
682-
}
676+
return requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler()
683677
}
684678

685679
private fun InputConnection.wrapWithBackSpaceHandler(): InputConnection {
@@ -705,7 +699,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
705699
private fun shouldOverridePredictiveTextBehavior(): Boolean {
706700
val currentKeyboard = Settings.Secure.getString(context.contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD)
707701
return Build.MANUFACTURER.lowercase(Locale.US) == "samsung" && Build.VERSION.SDK_INT >= 33 &&
708-
(currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard")) && overrideSamsungPredictiveBehavior
702+
(currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard"))
709703
}
710704

711705
// Setup the keyListener(s) for Backspace and Enter key.
@@ -1778,11 +1772,13 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
17781772
bypassMediaDeletedListener = false
17791773
}
17801774

1781-
// removes Grammarly suggestions from default keyboard on Samsung devices on Android 13 (API 33)
1775+
// removes auto-correct from default keyboard on Samsung devices on Android 13 (API 33)
17821776
// Grammarly implementation is often messing spans and cursor position, as described here:
17831777
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/1023
17841778
fun enableSamsungPredictiveBehaviorOverride() {
1785-
overrideSamsungPredictiveBehavior = true
1779+
if(shouldOverridePredictiveTextBehavior()){
1780+
inputType = inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
1781+
}
17861782
}
17871783

17881784
fun isMediaDeletedListenerDisabled(): Boolean {

0 commit comments

Comments
 (0)