Skip to content

Commit

Permalink
Disabling auto-correct only when keyboard changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
khaykov committed Oct 11, 2023
1 parent 03e05a7 commit 73c889a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 73c889a

Please sign in to comment.