Skip to content

Commit d2dc725

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 826f696 commit d2dc725

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
@@ -765,6 +765,25 @@ abstract class AutocompleteQuery {
765765
return compatibilityNormalized.replaceAll(_regExpStripMarkCharacters, '');
766766
}
767767

768+
NameMatchQuality? _matchName({
769+
required String normalizedName,
770+
required List<String> normalizedNameWords,
771+
}) {
772+
if (normalizedName.startsWith(_normalized)) {
773+
if (normalizedName.length == _normalized.length) {
774+
return NameMatchQuality.exact;
775+
} else {
776+
return NameMatchQuality.totalPrefix;
777+
}
778+
}
779+
780+
if (_testContainsQueryWords(normalizedNameWords)) {
781+
return NameMatchQuality.wordPrefixes;
782+
}
783+
784+
return null;
785+
}
786+
768787
/// Whether all of this query's words have matches in [words],
769788
/// insensitively to case and diacritics, that appear in order.
770789
///
@@ -790,8 +809,8 @@ abstract class AutocompleteQuery {
790809
}
791810
}
792811

793-
/// The match quality of a [User.fullName] or [UserGroup.name]
794-
/// to a mention autocomplete query.
812+
/// The match quality of some kind of name (e.g. [User.fullName])
813+
/// to an autocomplete query.
795814
///
796815
/// All matches are case-insensitive.
797816
enum NameMatchQuality {
@@ -868,25 +887,6 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
868887
nameMatchQuality: nameMatchQuality, matchesEmail: matchesEmail));
869888
}
870889

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

0 commit comments

Comments
 (0)