keyboard: one space after picking a suggestion no longer becomes a period
- Commit
90963eeefa44a67aeaf62e5f7a1d4acf3358b3e6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 03:27 UTC (5 days ago)
- Parents
d69b222
Double-space-period armed on any committed space: accepting a suggestion commits the word plus a trailing space and set lastSpaceTime, so a single intentional space within a second afterward took the delete-and-commit-'. ' path โ the user typed two spaces and got 'hello. '. The timer also survived field switches, so a first space in a fresh field could become a period there too. lastSpaceTime now records only a genuine space press in this field: commitSuggestion no longer arms it (two real presses still produce '. '), and onStartInputView resets it per field. onSpace/commitSuggestion gained InputConnection cores so the behaviour is testable against a fake field. Three new tests failed pre-fix on the suggestion and cross-field cases; dictionary/autocorrect was verified against an independent oracle over 53,710 generated typos, and composers, emoji, clipboard, voice and layout switching were audited and cleared. Verified: :keyboard:testDevUnitTest 194 tests and lint pass.
Diff
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.ktindex a6b6ce1df2..ad94e3f832 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardService.kt@@ -110,6 +110,12 @@ class KeyboardService : InputMethodService(), internal var bopomofoSpellings: Map<String, String> = emptyMap() internal var loadingChinese = false + /**+ * When the user last *pressed* space in the current field, for double-space-period.+ * Only a press in [KeyboardService.onSpace] may set it: arming it from a suggestion+ * pick's automatic trailing space (or leaving it over a field switch) made a single+ * press come out as ". ".+ */ internal var lastSpaceTime = 0L internal var lastShiftTime = 0L @@ -215,6 +221,9 @@ class KeyboardService : InputMethodService(), super.onStartInputView(info, restarting) composing.setLength(0) pendingComposition = ""+ // A new field starts a new double-space sequence: a space pressed in the+ // previous field must not turn this field's first space into ". ".+ lastSpaceTime = 0L before.onStartInput(info.initialSelStart, info.initialSelEnd) // Open on whatever subtype the system currently has selected for us, so the app's // active layout tracks the framework (e.g. after a system-level switch).
keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.ktindex 1cbdd4c074..0089889504 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/platform/ime/KeyboardServiceKeyOps.kt@@ -2,6 +2,7 @@ package com.vayunmathur.keyboard.platform.ime import android.os.SystemClock import android.view.KeyEvent+import android.view.inputmethod.InputConnection import com.vayunmathur.keyboard.domain.ShiftState /**@@ -116,6 +117,11 @@ internal fun KeyboardService.onSpace() { // Multi-word emoji names are common ("cat face"), so space is part of the query. if (typeIntoSearch(" ")) return val ic = currentInputConnection ?: return+ onSpace(ic)+}++/** Space against an explicit connection, so tests can drive it with a fake field. */+internal fun KeyboardService.onSpace(ic: InputConnection) { val engine = composer if (engine != null) { // In a CJK engine space means "take the best candidate", not "type a space".@@ -166,6 +172,11 @@ internal fun KeyboardService.onShift() { internal fun KeyboardService.commitSuggestion(word: String) { feedback() val ic = currentInputConnection ?: return+ commitSuggestion(ic, word)+}++/** Suggestion pick against an explicit connection, so tests can drive it with a fake field. */+internal fun KeyboardService.commitSuggestion(ic: InputConnection, word: String) { val engine = composer if (engine != null) { // A picked candidate is the character itself; no trailing space, unlike a word.@@ -176,7 +187,9 @@ internal fun KeyboardService.commitSuggestion(word: String) { finishComposing(ic) commit(ic, " ") composing.setLength(0)- lastSpaceTime = SystemClock.uptimeMillis()+ // Deliberately not arming the double-space timer: this trailing space is the+ // keyboard's, not a space press, so counting it made a single following press+ // come out as ". " โ a period the user never typed. kbState.suggestions = emptyList() updateAutoCapShift() }
keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.ktindex b41861349a..ecac59da89 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/platform/ime/ServiceOpsTest.kt@@ -256,6 +256,53 @@ class ServiceOpsTest { assertNull(service.kbState.clipSuggestion) } + /**+ * Regression: picking a suggestion commits the word plus a trailing space, but that+ * space is not a space *press*. Arming the double-space timer with it turned the+ * user's very next single space press into ". " โ a period they never typed.+ */+ @Test+ fun `a single space after picking a suggestion stays a space`() {+ val ic = FakeInputConnection()+ service.before.fill("")+ // Long ago, not 0: Robolectric's uptime clock starts near 0, where the+ // production "never" sentinel would still look like a fresh press.+ service.lastSpaceTime = android.os.SystemClock.uptimeMillis() - 60_000L+ service.composing.append("helo")+ service.commitSuggestion(ic, "hello")+ assertEquals("hello ", service.before.peek()?.toString())+ service.onSpace(ic)+ assertEquals(0, ic.deletedCodePoints, "one space press must not delete the trailing space")+ assertEquals(" ", ic.committed.last())+ assertEquals("hello ", service.before.peek()?.toString())+ }++ /** The feature itself still works: two real presses in quick succession make ". ". */+ @Test+ fun `two space presses still make a period`() {+ val ic = FakeInputConnection()+ service.before.fill("hi")+ service.onSpace(ic)+ service.onSpace(ic)+ assertEquals(1, ic.deletedCodePoints)+ assertEquals(". ", ic.committed.last())+ assertEquals("hi. ", service.before.peek()?.toString())+ }++ /** A space pressed in the previous field must not arm the timer in the next one. */+ @Test+ fun `starting a new field disarms the double-space timer`() {+ service.lastSpaceTime = android.os.SystemClock.uptimeMillis()+ service.onStartInputView(+ EditorInfo().apply {+ inputType = InputType.TYPE_CLASS_TEXT+ initialSelStart = 0; initialSelEnd = 0+ },+ restarting = false,+ )+ assertEquals(0L, service.lastSpaceTime)+ }+ @Test fun `commitEmoji remembers recent and leaves search`() { service.kbState.emojiData = com.vayunmathur.keyboard.data.EmojiData.BUILTIN