Skip to content

Commit 6c3db9c

Browse files
Ayush-Patel-56BrayanDSO
authored andcommitted
fix(ManageNoteTypes): Make search case-insensitive
This commit improves the search functionality in ManageNoteTypes: - Updates the filter logic to be case-insensitive for better usability. - Fixes a bug where the search query update would reset the cursor position, preventing rapid deletion.
1 parent 5666b15 commit 6c3db9c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNoteTypesViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ManageNoteTypesViewModel : ViewModel() {
7575
_state.update { oldState ->
7676
val matchedNoteTypes =
7777
oldState.noteTypes.map {
78-
it.copy(shouldBeDisplayed = it.name.contains(query))
78+
it.copy(shouldBeDisplayed = it.name.contains(query, ignoreCase = true))
7979
}
8080
oldState.copy(isLoading = false, noteTypes = matchedNoteTypes, searchQuery = query)
8181
}

AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypes.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ class ManageNotetypes : AnkiActivity(R.layout.activity_manage_note_types) {
177177
val searchMenuItem =
178178
findViewById<Toolbar>(R.id.toolbar).menu?.findItem(R.id.search_item)
179179
val searchView = searchMenuItem?.actionView as? AccessibleSearchView
180-
searchView?.setQuery(state.searchQuery, false)
180+
// Avoid resetting cursor position if query hasn't changed
181+
if (searchView?.query.toString() != state.searchQuery) {
182+
searchView?.setQuery(state.searchQuery, false)
183+
}
181184
}
182185
binding.selectionToolbar.isVisible = state.isInMultiSelectMode
183186
val selectedCount = state.noteTypes.count { it.isSelected }

AnkiDroid/src/test/java/com/ichi2/anki/notetype/ManageNoteTypesViewModelTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ class ManageNoteTypesViewModelTest : RobolectricTest() {
159159
assertTrue(viewModel.noteTypeForName(testName2).isSelected)
160160
}
161161

162+
@Test
163+
fun `filtering is case insensitive`() =
164+
runTest {
165+
val testName = "MixedCaseName"
166+
addStandardNoteType(testName, arrayOf("front", "back"), "", "")
167+
val viewModel = ManageNoteTypesViewModel()
168+
viewModel.filter("mixedcasename")
169+
val currentlyDisplayed =
170+
viewModel.state.value.noteTypes
171+
.filter { it.shouldBeDisplayed }
172+
assertThat(currentlyDisplayed, hasSize(1))
173+
assertThat(currentlyDisplayed.map { it.name }, hasItems(testName))
174+
}
175+
162176
@Test
163177
fun `removal failure in multiple selection returns expected exception`() =
164178
runTest {

0 commit comments

Comments
 (0)