Voice typing a tag with spaces duplicates the text

Open
#23,369 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
frontend, mobile

Research direction

Start with TagNameInputFilterTest.kt, which reproduces the duplicate text by sending successive composing updates through an EditText input connection. Find where the tag dialog fields install tagNameInputFilter and trace how it handles composing text that contains spaces. Confirm the fix by checking that the test's final text is cell::biology::is.

Written by the indexing model from the issue text.

Description

Assisted-by: Opus 5.5 max

Subject: [EXISTING] Voice typing a tag with spaces duplicates the text

When an IME updates composing text containing a space, as voice typing does in the tag dialog fields, the converted text is inserted twice.

⚠️ This issue existed before the PR and should likely be split off into a separate issue. This PR extends the trigger to ideographic spaces.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/tags/TagNameInputFilterTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/tags/TagNameInputFilterTest.kt
new file mode 100644
index 0000000000..de09d488b3
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/tags/TagNameInputFilterTest.kt
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.tags
+
+import android.view.inputmethod.EditorInfo
+import android.widget.EditText
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.junit.Test
+import org.junit.runner.RunWith
+import kotlin.test.assertEquals
+
+@RunWith(AndroidJUnit4::class)
+class TagNameInputFilterTest {
+    @Test
+    fun `updating composing text that contains a space replaces the composition`() {
+        val editText = EditText(ApplicationProvider.getApplicationContext())
+        editText.filters = arrayOf(tagNameInputFilter)
+        val inputConnection = editText.onCreateInputConnection(EditorInfo())
+
+        // Voice typing streams a growing phrase as composing text
+        inputConnection.setComposingText("cell biology", 1)
+        inputConnection.setComposingText("cell biology is", 1)
+
+        assertEquals("cell::biology::is", editText.text.toString())
+    }
+}

Originally posted by @criticalAY in https://github.com/ankidroid/Anki-Android/pull/22849#pullrequestreview-5940650367

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
1d 11h
Merged PRs (30d)
383

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.