Skip to content

Commit fe12475

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 —— 2025-11, only the emoji autocomplete matching mechanism is different).
1 parent b1e4f1c commit fe12475

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/model/autocomplete.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,25 @@ abstract class AutocompleteQuery {
736736
return compatibilityNormalized.replaceAll(_regExpStripMarkCharacters, '');
737737
}
738738

739+
NameMatchQuality? _matchName({
740+
required String normalizedName,
741+
required List<String> normalizedNameWords,
742+
}) {
743+
if (normalizedName.startsWith(_normalized)) {
744+
if (normalizedName.length == _normalized.length) {
745+
return NameMatchQuality.exact;
746+
} else {
747+
return NameMatchQuality.totalPrefix;
748+
}
749+
}
750+
751+
if (_testContainsQueryWords(normalizedNameWords)) {
752+
return NameMatchQuality.wordPrefixes;
753+
}
754+
755+
return null;
756+
}
757+
739758
/// Whether all of this query's words have matches in [words],
740759
/// insensitively to case and diacritics, that appear in order.
741760
///
@@ -761,8 +780,8 @@ abstract class AutocompleteQuery {
761780
}
762781
}
763782

764-
/// The match quality of a [User.fullName] or [UserGroup.name]
765-
/// to a mention autocomplete query.
783+
/// The match quality of some kind of name (e.g. [User.fullName])
784+
/// to an autocomplete query.
766785
///
767786
/// All matches are case-insensitive.
768787
enum NameMatchQuality {
@@ -839,25 +858,6 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
839858
nameMatchQuality: nameMatchQuality, matchesEmail: matchesEmail));
840859
}
841860

842-
NameMatchQuality? _matchName({
843-
required String normalizedName,
844-
required List<String> normalizedNameWords,
845-
}) {
846-
if (normalizedName.startsWith(_normalized)) {
847-
if (normalizedName.length == _normalized.length) {
848-
return NameMatchQuality.exact;
849-
} else {
850-
return NameMatchQuality.totalPrefix;
851-
}
852-
}
853-
854-
if (_testContainsQueryWords(normalizedNameWords)) {
855-
return NameMatchQuality.wordPrefixes;
856-
}
857-
858-
return null;
859-
}
860-
861861
bool _matchEmail(User user, AutocompleteDataCache cache) {
862862
final normalizedEmail = cache.normalizedEmailForUser(user);
863863
if (normalizedEmail == null) return false; // Email not known

0 commit comments

Comments
 (0)