Skip to content

Commit b56b3b4

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 2b4ef42 commit b56b3b4

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
@@ -175,13 +175,14 @@ void main() {
175175
check(findText(includePlaceholders: false, 'Muted user')).findsNothing();
176176
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
177177
check(findText(includePlaceholders: false, 'Charlie Carter')).findsOne();
178-
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(2);
178+
check(findText(includePlaceholders: false, 'Édith Piaf')).findsOne();
179+
check(find.byIcon(ZulipIcons.check_circle_unchecked)).findsExactly(3);
179180
});
180181

181182
// TODO test sorting by recent-DMs
182183
// TODO test that scroll position resets on query change
183184

184-
testWidgets('search is case-insensitive', (tester) async {
185+
testWidgets('search is case- and diacritics-insensitive', (tester) async {
185186
await setupSheet(tester, users: testUsers);
186187
await tester.enterText(find.byType(TextField), 'alice');
187188
await tester.pump();
@@ -190,6 +191,14 @@ void main() {
190191
await tester.enterText(find.byType(TextField), 'ALICE');
191192
await tester.pump();
192193
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
194+
195+
await tester.enterText(find.byType(TextField), 'alicé');
196+
await tester.pump();
197+
check(findText(includePlaceholders: false, 'Alice Anderson')).findsOne();
198+
199+
await tester.enterText(find.byType(TextField), 'edith');
200+
await tester.pump();
201+
check(findText(includePlaceholders: false, 'Édith Piaf')).findsOne();
193202
});
194203

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

0 commit comments

Comments
 (0)