Skip to content

Commit a6055d5

Browse files
chrisbobbegnprice
authored andcommitted
autocomplete [nfc]: Renames/doc changes for explicitness about normalizing
1 parent 14b7fdf commit a6055d5

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/model/autocomplete.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,15 @@ abstract class AutocompleteQuery {
698698

699699
late final List<String> _lowercaseWords;
700700

701-
/// Whether all of this query's words have matches in [words] that appear in order.
701+
/// Whether all of this query's words have matches in [words],
702+
/// modulo case, that appear in order.
702703
///
703704
/// A "match" means the word in [words] starts with the query word.
705+
///
706+
/// [words] must all be lowercased.
704707
bool _testContainsQueryWords(List<String> words) {
705-
// TODO(#237) test with diacritics stripped, where appropriate
708+
// TODO(#237) test with diacritics stripped, where appropriate,
709+
// and update dartdoc's summary line and its restriction about [words].
706710
int wordsIndex = 0;
707711
int queryWordsIndex = 0;
708712
while (true) {
@@ -774,7 +778,7 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
774778
}
775779

776780
bool _testName(User user, AutocompleteDataCache cache) {
777-
return _testContainsQueryWords(cache.nameWordsForUser(user));
781+
return _testContainsQueryWords(cache.normalizedNameWordsForUser(user));
778782
}
779783

780784
/// A measure of a wildcard result's quality in the context of the query,
@@ -827,20 +831,21 @@ extension WildcardMentionOptionExtension on WildcardMentionOption {
827831
class AutocompleteDataCache {
828832
final Map<int, String> _normalizedNamesByUser = {};
829833

830-
/// The lowercase `fullName` of [user].
834+
/// The normalized `fullName` of [user].
831835
String normalizedNameForUser(User user) {
832836
return _normalizedNamesByUser[user.userId] ??= user.fullName.toLowerCase();
833837
}
834838

835-
final Map<int, List<String>> _nameWordsByUser = {};
839+
final Map<int, List<String>> _normalizedNameWordsByUser = {};
836840

837-
List<String> nameWordsForUser(User user) {
838-
return _nameWordsByUser[user.userId] ??= normalizedNameForUser(user).split(' ');
841+
List<String> normalizedNameWordsForUser(User user) {
842+
return _normalizedNameWordsByUser[user.userId]
843+
??= normalizedNameForUser(user).split(' ');
839844
}
840845

841846
void invalidateUser(int userId) {
842847
_normalizedNamesByUser.remove(userId);
843-
_nameWordsByUser.remove(userId);
848+
_normalizedNameWordsByUser.remove(userId);
844849
}
845850
}
846851

0 commit comments

Comments
 (0)