From 79e6df588f126e94fb00eb89c7595a42610cac93 Mon Sep 17 00:00:00 2001 From: joashrajin Date: Mon, 29 Jun 2026 09:12:16 +0200 Subject: [PATCH] Scope Samsung keyboard suggestion interception to checklist edits SamsungInputConnection.commitText() suppressed every spellcheck/autocorrect commit that carried a SuggestionSpan, in order to protect checklist (CheckableSpan) spans from being corrupted when the Samsung keyboard replaced editor content. On One UI 7/8 (e.g. Galaxy S25, Android 16) this fires on ordinary prose too, so autocorrect-on-space is never applied and typos "stick" instead of being corrected. The bug it originally guarded against was tied to the in-keyboard Grammarly plugin that Samsung removed in 2024. Only take the protective path when the edited region (the composing region, or the selection when there is none) actually contains a CheckableSpan; otherwise forward to the keyboard's normal commit so autocorrect works. Checklist protection is unchanged where it is actually needed. --- RELEASE-NOTES.txt | 1 + .../widgets/SamsungInputConnection.kt | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 8f2cc3b58..0d379f8ce 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,5 +1,6 @@ 2.39 ----- +* Fixed autocorrect not being applied in the editor on Samsung devices [#1840](https://github.com/Automattic/simplenote-android/pull/1840) 2.38 ----- diff --git a/Simplenote/src/main/java/com/automattic/simplenote/widgets/SamsungInputConnection.kt b/Simplenote/src/main/java/com/automattic/simplenote/widgets/SamsungInputConnection.kt index 245b5c386..d6ce74501 100644 --- a/Simplenote/src/main/java/com/automattic/simplenote/widgets/SamsungInputConnection.kt +++ b/Simplenote/src/main/java/com/automattic/simplenote/widgets/SamsungInputConnection.kt @@ -73,6 +73,34 @@ class SamsungInputConnection( return baseInputConnection.setComposingText(text, newCursorPosition) } + /** + * The protective branch in [commitText] exists only to keep checklist spans ([CheckableSpan]) from being + * corrupted when the Samsung keyboard replaces editor content. If the region the keyboard is about to edit + * (the composing region, or the current selection if there is none) contains no checklist span, there is + * nothing to protect, so we let the keyboard apply its normal autocorrect/suggestion behavior instead of + * suppressing it. + */ + private fun editedRegionHasCheckableSpan(): Boolean { + val editable = editable + var start = getComposingSpanStart(editable) + var end = getComposingSpanEnd(editable) + + if (start == -1 || end == -1) { + start = Selection.getSelectionStart(editable) + end = Selection.getSelectionEnd(editable) + } + + if (start < 0) start = 0 + if (end < 0) end = 0 + if (end < start) { + val tmp = start + start = end + end = tmp + } + + return editable.getSpans(start, end, CheckableSpan::class.java).isNotEmpty() + } + override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean { val incomingTextHasSuggestions = text is Spanned && text.getSpans(0, text.length, SuggestionSpan::class.java).isNotEmpty() @@ -81,7 +109,11 @@ class SamsungInputConnection( // but CheckableSpan spans are finicky, and tend to get messed when content of the editor is replaced. // In this method we do everything replaceText method of EditableInputConnection does, apart from actually // replacing text. Instead we copy the suggestions from incoming text into editor directly. - if (incomingTextHasSuggestions) { + // + // We only take this path when the edited region actually contains a checklist span; for plain text there + // is nothing to protect, so we fall through to the keyboard's normal autocorrect/suggestion handling + // instead of swallowing the correction (which previously broke autocorrect on every note). + if (incomingTextHasSuggestions && editedRegionHasCheckableSpan()) { AppLog.add( AppLog.Type.EDITOR, "Detected spellchecker trying to commit partial text with suggestions"