Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocomplete: Match insensitively to diacritics In @-mention results #588

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:diacritic/diacritic.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -301,7 +302,7 @@ class MentionAutocompleteQuery {
return false;
}

if (nameWords[nameWordsIndex].startsWith(_lowercaseWords[queryWordsIndex])) {
if (nameWords[nameWordsIndex].startsWith(removeDiacritics(_lowercaseWords[queryWordsIndex]))) {
queryWordsIndex++;
}
nameWordsIndex++;
Expand All @@ -326,7 +327,7 @@ class AutocompleteDataCache {
final Map<int, List<String>> _nameWordsByUser = {};

List<String> nameWordsForUser(User user) {
return _nameWordsByUser[user.userId] ??= user.fullName.toLowerCase().split(' ');
return _nameWordsByUser[user.userId] ??= removeDiacritics(user.fullName.toLowerCase()).split(' ');
}

void invalidateUser(int userId) {
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
diacritic:
dependency: "direct main"
description:
name: diacritic
sha256: "96db5db6149cbe4aa3cfcbfd170aca9b7648639be7e48025f9d458517f807fe4"
url: "https://pub.dev"
source: hosted
version: "0.1.5"
drift:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies:
url_launcher: ^6.1.11
url_launcher_android: ">=6.1.0"
sqlite3: ^2.4.0
diacritic: ^0.1.5

dev_dependencies:
flutter_driver:
Expand Down
5 changes: 5 additions & 0 deletions test/model/autocomplete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ void main() {
doCheck('full full', eg.user(fullName: 'Full Full Name'), true);
doCheck('full full', eg.user(fullName: 'Full Name Full'), true);

// assert that name checking is diacritic insensitive
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be enhanced with test groups but that will be against the pattern in this file, I imagine some little tweaks would be required.
I would prefer updating it but I try to follow the patterns I find in the codebase.
So.. what do you suggest?

doCheck('fűll ñámé', eg.user(fullName: 'Full Name'), true);
doCheck('fűll', eg.user(fullName: 'Full Name'), true);
doCheck('ñámé', eg.user(fullName: 'Full Name'), true);

doCheck('F', eg.user(fullName: ''), false); // Unlikely case, but should not crash
doCheck('Fully Named', eg.user(fullName: 'Full Name'), false);
doCheck('Full Name', eg.user(fullName: 'Full'), false);
Expand Down