keyboard: hide clip chip on clipboard page (#555)
- Commit
21e77eae96c067a32335e9e737969cadcf970284- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-12 17:34 UTC (23 days ago)
- Parents
6aee53e
Symptom (GitHub #555, item 8, second half): with something freshly copied, opening the clipboard page shows that clip twice, once as the suggestion chip in the strip and again as the first entry of the clipboard list directly below it. Cause: setPage() never dismissed the fresh-clip chip when the clipboard page opened, and Strip() draws the chip whenever clipSuggestion is set, on every page. The chip's own "open" button leads straight to the clipboard page, so the most natural way in produced the duplicate. Changes: - KeyboardServiceEmojiOps.setPage(): entering KeyboardPage.CLIPBOARD calls dismissClipSuggestion(). The chip is a one-time offer of the latest clip, timed out by CLIP_CHIP_MS (60 s) and already dropped on the first keypress; opening the full clipboard takes the offer up, so it shouldn't reappear when the user goes back to the letters. - KeyboardScreen.Strip(): the chip is not drawn while the clipboard page is showing. This covers a clip copied while the page is open (offerClip() fires from the clipboard listener), which would otherwise duplicate the new list head the same way. Not changed: item 8's other request, a permanent clipboard row, is a separate design question and stays out of this fix. User-visible effect: the clipboard page shows each clip once. Leaving the page doesn't bring the chip back for a clip already seen there. The chip on the letters and symbol pages behaves as before. Verification: - ServiceOpsTest: offerClip() then setPage(SYMBOLS) keeps the chip; setPage(CLIPBOARD) clears it and setPage(LETTERS) doesn't bring it back. - KeyboardScreenTest: with the clipboard page open and the same clip as both chip and list entry, its text appears exactly once; after switching back to the letters the chip is drawn again. - :keyboard compileDevKotlin, testDevUnitTest, lint and detekt in the build container.
Diff
keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.ktindex 253331093e..c93b88693c 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ime/KeyboardServiceEmojiOps.kt@@ -67,5 +67,9 @@ internal fun KeyboardService.setPage(page: KeyboardPage) { kbState.emojiQuery = null kbState.emojiResults = emptyList() }+ // The fresh-clip chip is an offer to open or paste that clip; opening the clipboard+ // page takes it up (the clip heads the list there), so the offer is spent rather than+ // left to reappear when the user comes back to the letters (#555).+ if (page == KeyboardPage.CLIPBOARD) dismissClipSuggestion() kbState.page = page }
keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt
diff --git a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.ktindex f79a10f60a..4559e12929 100644--- a/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt+++ b/keyboard/src/main/java/com/vayunmathur/keyboard/ui/KeyboardScreen.kt@@ -119,8 +119,10 @@ private fun Strip(state: KeyboardState, actions: ImeActions) { // offered before anything has been typed and the service drops it on the first keypress, // which is exactly when suggestions appear. The chip carries its own open button, so it // stands in for the whole strip rather than sitting beside the clipboard key.+ // Never above the clipboard page itself, which already lists that clip first: a copy+ // made while the page is open would otherwise draw it twice (#555). val clip = state.clipSuggestion- if (clip != null) {+ if (clip != null && state.page != KeyboardPage.CLIPBOARD) { ClipboardStrip( height = StripHeight, item = clip,
keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.ktindex 616ac47ce4..695cfec852 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ime/ServiceOpsTest.kt@@ -222,6 +222,21 @@ class ServiceOpsTest { assertEquals(KeyboardPage.SYMBOLS, service.kbState.page) } + @Test+ fun `opening the clipboard page spends the fresh-clip chip`() {+ val item = ClipItem(id = 991101, text = "just copied")+ service.offerClip(item)+ // Other pages leave the offer standing; it only gives up after CLIP_CHIP_MS.+ service.setPage(KeyboardPage.SYMBOLS)+ assertEquals(item, service.kbState.clipSuggestion)+ // The clipboard page lists the clip itself, so the chip is spent (#555)...+ service.setPage(KeyboardPage.CLIPBOARD)+ assertNull(service.kbState.clipSuggestion)+ // ...and coming back to the letters does not resurrect it.+ service.setPage(KeyboardPage.LETTERS)+ assertNull(service.kbState.clipSuggestion)+ }+ @Test fun `commitEmoji remembers recent and leaves search`() { service.kbState.emojiData = com.vayunmathur.keyboard.util.EmojiData.BUILTIN
keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt
diff --git a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.ktindex 23cc2db7eb..c49c16be9f 100644--- a/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt+++ b/keyboard/src/test/java/com/vayunmathur/keyboard/ui/KeyboardScreenTest.kt@@ -360,6 +360,24 @@ class KeyboardScreenTest { assertEquals(1, actions.clearClipsCalls) } + @Test+ fun `clip chip is not drawn above the clipboard page`() {+ // A clip copied while the page is open is both the chip and the head of the list;+ // it must show once, as the list entry (#555).+ val actions = RecordingActions()+ val clip = ClipItem(id = 44, text = "copied while open")+ val st = state {+ page = KeyboardPage.CLIPBOARD+ clips = listOf(clip)+ clipSuggestion = clip+ }+ rule.setContent { KeyboardScreen(st, actions) }+ assertEquals(1, rule.onAllNodesWithText("copied while open").fetchSemanticsNodes().size)+ // Back on the letters the chip is still on offer (until it times out).+ rule.runOnIdle { st.page = KeyboardPage.LETTERS }+ rule.onNodeWithText("copied while open").assertIsDisplayed()+ }+ @Test fun `clipboard page empty state`() { val actions = RecordingActions()