Skip to content

Commit 29778e0

Browse files
committed
autocomplete [nfc]: Renames/doc changes for explicitness about lowercase
1 parent d10ad86 commit 29778e0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/model/autocomplete.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,9 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
602602
static int compareByAlphabeticalOrder(User userA, User userB,
603603
{required PerAccountStore store}) {
604604
final userAName = store.autocompleteViewManager.autocompleteDataCache
605-
.normalizedNameForUser(userA);
605+
.lowercaseNameForUser(userA);
606606
final userBName = store.autocompleteViewManager.autocompleteDataCache
607-
.normalizedNameForUser(userB);
607+
.lowercaseNameForUser(userB);
608608
return userAName.compareTo(userBName); // TODO(i18n): add locale-aware sorting
609609
}
610610

@@ -698,9 +698,12 @@ 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+
/// case-insensitively, 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) {
705708
// TODO(#237) test with diacritics stripped, where appropriate
706709
int wordsIndex = 0;
@@ -774,7 +777,7 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
774777
}
775778

776779
bool _testName(User user, AutocompleteDataCache cache) {
777-
return _testContainsQueryWords(cache.nameWordsForUser(user));
780+
return _testContainsQueryWords(cache.lowercaseNameWordsForUser(user));
778781
}
779782

780783
/// A measure of a wildcard result's quality in the context of the query,
@@ -825,22 +828,22 @@ extension WildcardMentionOptionExtension on WildcardMentionOption {
825828
///
826829
/// An instance of this class is managed by [AutocompleteViewManager].
827830
class AutocompleteDataCache {
828-
final Map<int, String> _normalizedNamesByUser = {};
831+
final Map<int, String> _lowercaseNamesByUser = {};
829832

830833
/// The lowercase `fullName` of [user].
831-
String normalizedNameForUser(User user) {
832-
return _normalizedNamesByUser[user.userId] ??= user.fullName.toLowerCase();
834+
String lowercaseNameForUser(User user) {
835+
return _lowercaseNamesByUser[user.userId] ??= user.fullName.toLowerCase();
833836
}
834837

835-
final Map<int, List<String>> _nameWordsByUser = {};
838+
final Map<int, List<String>> _lowercaseNameWordsByUser = {};
836839

837-
List<String> nameWordsForUser(User user) {
838-
return _nameWordsByUser[user.userId] ??= normalizedNameForUser(user).split(' ');
840+
List<String> lowercaseNameWordsForUser(User user) {
841+
return _lowercaseNameWordsByUser[user.userId] ??= lowercaseNameForUser(user).split(' ');
839842
}
840843

841844
void invalidateUser(int userId) {
842-
_normalizedNamesByUser.remove(userId);
843-
_nameWordsByUser.remove(userId);
845+
_lowercaseNamesByUser.remove(userId);
846+
_lowercaseNameWordsByUser.remove(userId);
844847
}
845848
}
846849

0 commit comments

Comments
 (0)