Modern Apps git

← Modern-Apps.git

keyboard: a picked suggestion breaks the double-space sequence

Commit
7ba660bbe87e7fb581a13af4128d50b3dba02908
Author
Vayun Mathur <[email protected]>
When
2026-12-01 08:01 UTC (5 days ago)
Parents
86eda74
Type 'hi', press space (a genuine press arms the
double-space timer), type 't', tap the suggestion 'the'
(it commits with its own trailing space), then press space
once within a second — the field became 'hi the. ': one
press produced a period because the earlier press's timer
was still armed and text now ended '<letter> '. The landed
double-space fix stopped the pick from arming the timer,
but never disarmed a timer an earlier press had left
running, so press-pick-press read as a consecutive double
press.

commitSuggestion now disarms the timer (the pick breaks the
sequence), and onSpace honours 0L as the never-armed
sentinel — required for correctness, since raw subtraction
reads 0L as a fresh press whenever uptime is under 1 s. New
regression test drives press-pick-press and failed pre-fix;
the existing two-presses-make-a-period and
single-space-after-pick-stays-space tests still pass.
Autocorrect ranking, composers, clipboard sensitivity and
settings application were audited and cleared. Verified:
:keyboard:testDevUnitTest 195 tests and :keyboard:lint
BUILD SUCCESSFUL.

Diff

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 0089889504..95c234a28e 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@@ -140,7 +140,7 @@ internal fun KeyboardService.onSpace(ic: InputConnection) {     val now = SystemClock.uptimeMillis()     val doubleSpace = kbState.settings.doubleSpacePeriod && text.length >= 2 &&         text[text.length - 1] == ' ' && text[text.length - 2].isLetterOrDigit() &&-        now - lastSpaceTime < 1000+        lastSpaceTime != 0L && now - lastSpaceTime < 1000     if (doubleSpace) {         deleteBackward(ic)         commit(ic, ". ")@@ -189,7 +189,10 @@ internal fun KeyboardService.commitSuggestion(ic: InputConnection, word: String)     composing.setLength(0)     // 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.+    // come out as ". " — a period the user never typed. The pick also disarms a+    // timer an earlier genuine press left running: a word now sits between the+    // two presses, so they are no longer the consecutive pair the period is for.+    lastSpaceTime = 0L     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 ecac59da89..127513a4d3 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@@ -277,6 +277,27 @@ class ServiceOpsTest {         assertEquals("hello  ", service.before.peek()?.toString())     } +    /**+     * Regression (deeper variant): a genuine space press, then a suggestion pick, then+     * one more space press. The pick commits a word plus its own trailing space between+     * the two presses, so the presses are not consecutive — yet the first press's timer+     * was still armed, and the single press after the picked word came out as ". ".+     */+    @Test+    fun `a space press before picking a suggestion does not make the next press a period`() {+        val ic = FakeInputConnection()+        service.before.fill("hi")+        service.onSpace(ic)+        assertEquals("hi ", service.before.peek()?.toString())+        service.composing.append("t")+        service.commitSuggestion(ic, "the")+        assertEquals("hi the ", service.before.peek()?.toString())+        service.onSpace(ic)+        assertEquals(0, ic.deletedCodePoints, "one space press after a pick must not delete the trailing space")+        assertEquals(" ", ic.committed.last())+        assertEquals("hi the  ", 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`() {