Skip to content

Commit 73c889a

Browse files
committed
Disabling auto-correct only when keyboard changes.
1 parent 03e05a7 commit 73c889a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
239239
private var bypassObservationQueue: Boolean = false
240240
private var bypassMediaDeletedListener: Boolean = false
241241
private var bypassCrashPreventerInputFilter: Boolean = false
242+
private var overrideSamsungPredictiveBehavior: Boolean = false
242243

243244
var initialEditorContentParsedSHA256: ByteArray = ByteArray(0)
244245

@@ -673,7 +674,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
673674
}
674675

675676
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection {
676-
return requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler()
677+
val inputConnection = requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler()
678+
679+
if (shouldOverridePredictiveTextBehavior()) {
680+
AppLog.d(AppLog.T.EDITOR, "Disabling autocorrect on Samsung device with Samsung Keyboard with API 33")
681+
outAttrs.inputType = outAttrs.inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
682+
}
683+
684+
return inputConnection
677685
}
678686

679687
private fun InputConnection.wrapWithBackSpaceHandler(): InputConnection {
@@ -699,7 +707,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
699707
private fun shouldOverridePredictiveTextBehavior(): Boolean {
700708
val currentKeyboard = Settings.Secure.getString(context.contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD)
701709
return Build.MANUFACTURER.lowercase(Locale.US) == "samsung" && Build.VERSION.SDK_INT >= 33 &&
702-
(currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard"))
710+
(currentKeyboard !== null && currentKeyboard.startsWith("com.samsung.android.honeyboard")) && overrideSamsungPredictiveBehavior
703711
}
704712

705713
// Setup the keyListener(s) for Backspace and Enter key.
@@ -1776,9 +1784,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
17761784
// Grammarly implementation is often messing spans and cursor position, as described here:
17771785
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/1023
17781786
fun enableSamsungPredictiveBehaviorOverride() {
1779-
if(shouldOverridePredictiveTextBehavior()){
1780-
inputType = inputType or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
1781-
}
1787+
overrideSamsungPredictiveBehavior = true
17821788
}
17831789

17841790
fun isMediaDeletedListenerDisabled(): Boolean {

0 commit comments

Comments
 (0)