Skip to content

Commit 79e6df5

Browse files
committed
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.
1 parent b8e570b commit 79e6df5

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.39
22
-----
3+
* Fixed autocorrect not being applied in the editor on Samsung devices [#1840](https://github.com/Automattic/simplenote-android/pull/1840)
34

45
2.38
56
-----

Simplenote/src/main/java/com/automattic/simplenote/widgets/SamsungInputConnection.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ class SamsungInputConnection(
7373
return baseInputConnection.setComposingText(text, newCursorPosition)
7474
}
7575

76+
/**
77+
* The protective branch in [commitText] exists only to keep checklist spans ([CheckableSpan]) from being
78+
* corrupted when the Samsung keyboard replaces editor content. If the region the keyboard is about to edit
79+
* (the composing region, or the current selection if there is none) contains no checklist span, there is
80+
* nothing to protect, so we let the keyboard apply its normal autocorrect/suggestion behavior instead of
81+
* suppressing it.
82+
*/
83+
private fun editedRegionHasCheckableSpan(): Boolean {
84+
val editable = editable
85+
var start = getComposingSpanStart(editable)
86+
var end = getComposingSpanEnd(editable)
87+
88+
if (start == -1 || end == -1) {
89+
start = Selection.getSelectionStart(editable)
90+
end = Selection.getSelectionEnd(editable)
91+
}
92+
93+
if (start < 0) start = 0
94+
if (end < 0) end = 0
95+
if (end < start) {
96+
val tmp = start
97+
start = end
98+
end = tmp
99+
}
100+
101+
return editable.getSpans(start, end, CheckableSpan::class.java).isNotEmpty()
102+
}
103+
76104
override fun commitText(text: CharSequence?, newCursorPosition: Int): Boolean {
77105
val incomingTextHasSuggestions = text is Spanned &&
78106
text.getSpans(0, text.length, SuggestionSpan::class.java).isNotEmpty()
@@ -81,7 +109,11 @@ class SamsungInputConnection(
81109
// but CheckableSpan spans are finicky, and tend to get messed when content of the editor is replaced.
82110
// In this method we do everything replaceText method of EditableInputConnection does, apart from actually
83111
// replacing text. Instead we copy the suggestions from incoming text into editor directly.
84-
if (incomingTextHasSuggestions) {
112+
//
113+
// We only take this path when the edited region actually contains a checklist span; for plain text there
114+
// is nothing to protect, so we fall through to the keyboard's normal autocorrect/suggestion handling
115+
// instead of swallowing the correction (which previously broke autocorrect on every note).
116+
if (incomingTextHasSuggestions && editedRegionHasCheckableSpan()) {
85117
AppLog.add(
86118
AppLog.Type.EDITOR,
87119
"Detected spellchecker trying to commit partial text with suggestions"

0 commit comments

Comments
 (0)