Skip to content

Commit 129de2c

Browse files
committed
autocomplete [nfc]: Move _matchName up to AutocompleteQuery
Also, generalize the dartdoc of NameMatchQuality. For almost all types of autocompletes, the matching mechanism/quality to an autocomplete query seems to be the same with rare exceptions (at the time of writing this, only the emoji autocomplete matching mechanism is different).
1 parent 195951c commit 129de2c

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

lib/model/autocomplete.dart

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,25 @@ abstract class AutocompleteQuery {
762762
return compatibilityNormalized.replaceAll(_regExpStripMarkCharacters, '');
763763
}
764764

765+
NameMatchQuality? _matchName({
766+
required String normalizedName,
767+
required List<String> normalizedNameWords,
768+
}) {
769+
if (normalizedName.startsWith(_normalized)) {
770+
if (normalizedName.length == _normalized.length) {
771+
return NameMatchQuality.exact;
772+
} else {
773+
return NameMatchQuality.totalPrefix;
774+
}
775+
}
776+
777+
if (_testContainsQueryWords(normalizedNameWords)) {
778+
return NameMatchQuality.wordPrefixes;
779+
}
780+
781+
return null;
782+
}
783+
765784
/// Whether all of this query's words have matches in [words],
766785
/// insensitively to case and diacritics, that appear in order.
767786
///
@@ -787,8 +806,7 @@ abstract class AutocompleteQuery {
787806
}
788807
}
789808

790-
/// The match quality of a [User.fullName] or [UserGroup.name]
791-
/// to a mention autocomplete query.
809+
/// The match quality of a name or text to an autocomplete query.
792810
///
793811
/// All matches are case-insensitive.
794812
enum NameMatchQuality {
@@ -864,25 +882,6 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
864882
rank: _rankUserResult(nameMatchQuality, matchesEmail: matchesEmail));
865883
}
866884

867-
NameMatchQuality? _matchName({
868-
required String normalizedName,
869-
required List<String> normalizedNameWords,
870-
}) {
871-
if (normalizedName.startsWith(_normalized)) {
872-
if (normalizedName.length == _normalized.length) {
873-
return NameMatchQuality.exact;
874-
} else {
875-
return NameMatchQuality.totalPrefix;
876-
}
877-
}
878-
879-
if (_testContainsQueryWords(normalizedNameWords)) {
880-
return NameMatchQuality.wordPrefixes;
881-
}
882-
883-
return null;
884-
}
885-
886885
bool _matchEmail(User user, AutocompleteDataCache cache) {
887886
final normalizedEmail = cache.normalizedEmailForUser(user);
888887
if (normalizedEmail == null) return false; // Email not known

0 commit comments

Comments
 (0)