Skip to content

Commit 0ade8a3

Browse files
committed
new_dm_sheet: Make searching insensitive to diacritics
We didn't have an issue for this, but I guess it would've been quietly fixed in a future where we've switched the filtering/sorting fully over to our autocomplete machinery, which we have a TODO for.
1 parent bead286 commit 0ade8a3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/widgets/new_dm_sheet.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ class _NewDmPickerState extends State<NewDmPicker> with PerAccountStoreAwareStat
8787
void _updateFilteredUsers(PerAccountStore store) {
8888
final excludeSelfUser = selectedUserIds.isNotEmpty
8989
&& !selectedUserIds.contains(store.selfUserId);
90-
final searchTextLower = searchController.text.toLowerCase();
90+
final normalizedQuery =
91+
AutocompleteQuery.lowercaseAndStripDiacritics(searchController.text);
9192

9293
final result = <User>[];
9394
for (final user in sortedUsers) {
9495
if (excludeSelfUser && user.userId == store.selfUserId) continue;
95-
if (user.fullName.toLowerCase().contains(searchTextLower)) {
96+
final normalizedName = AutocompleteQuery.lowercaseAndStripDiacritics(user.fullName);
97+
if (normalizedName.contains(normalizedQuery)) {
9698
result.add(user);
9799
}
98100
}

test/widgets/new_dm_sheet_test.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,14 @@ void main() {
179179
check(findText(includePlaceholders: false, 'Muted user')).findsNothing();
180180
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
181181
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();
182-
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(2);
182+
check(findText(includePlaceholders: false, 'Édith Piaf')).findsOne();
183+
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);
183184
});
184185

185186
// TODO test sorting by recent-DMs
186187
// TODO test that scroll position resets on query change
187188

188-
testWidgets('search is case-insensitive', (tester) async {
189+
testWidgets('search is case- and diacritics-insensitive', (tester) async {
189190
await setupSheet(tester, users: testUsers);
190191
await tester.enterText(find.byType(TextField), 'alice');
191192
await tester.pump();
@@ -194,6 +195,14 @@ void main() {
194195
await tester.enterText(find.byType(TextField), 'ALICE');
195196
await tester.pump();
196197
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
198+
199+
await tester.enterText(find.byType(TextField), 'alicé');
200+
await tester.pump();
201+
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
202+
203+
await tester.enterText(find.byType(TextField), 'edith');
204+
await tester.pump();
205+
check(findText(includePlaceholders: false, 'Édith Piaf')).findsOne();
197206
});
198207

199208
testWidgets('partial name and last name search handling', (tester) async {

0 commit comments

Comments
 (0)