Skip to content

Commit

Permalink
Merge pull request #1063 from wordpress-mobile/issue/disabled-autocor…
Browse files Browse the repository at this point in the history
…rect-on-certain-samsung-devices

Disabled autocorrect on Samsung device with Samsung keyboard on API 33+
  • Loading branch information
nbradbury authored Oct 12, 2023
2 parents caf8f43 + cff5d94 commit 1614ca1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 194 deletions.
16 changes: 9 additions & 7 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import android.os.Parcelable
import android.provider.Settings
import android.text.Editable
import android.text.InputFilter
import android.text.InputType
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
Expand Down Expand Up @@ -695,13 +696,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
}

override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection {
val baseInputConnection = requireNotNull(super.onCreateInputConnection(outAttrs)).wrapWithBackSpaceHandler()
return if (shouldOverridePredictiveTextBehavior()) {
AppLog.d(AppLog.T.EDITOR, "Overriding predictive text behavior on Samsung device with Samsung Keyboard with API 33")
SamsungInputConnection(this, baseInputConnection)
} else {
baseInputConnection
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 {
Expand Down Expand Up @@ -1800,7 +1802,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
bypassMediaDeletedListener = false
}

// removes Grammarly suggestions from default keyboard on Samsung devices on Android 13 (API 33)
// removes auto-correct from default keyboard on Samsung devices on Android 13 (API 33)
// Grammarly implementation is often messing spans and cursor position, as described here:
// https://github.com/wordpress-mobile/AztecEditor-Android/issues/1023
fun enableSamsungPredictiveBehaviorOverride() {
Expand Down
187 changes: 0 additions & 187 deletions aztec/src/main/kotlin/org/wordpress/aztec/SamsungInputConnection.kt

This file was deleted.

0 comments on commit 1614ca1

Please sign in to comment.