From 4ee0675b140b19fcad25c4969d33b5433fe8aead Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 7 Dec 2024 01:26:57 -0800 Subject: [PATCH] wip precompute ranks fully --- lib/model/autocomplete.dart | 6 +++--- lib/model/emoji.dart | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/model/autocomplete.dart b/lib/model/autocomplete.dart index 00623f42f5..77bfb9e537 100644 --- a/lib/model/autocomplete.dart +++ b/lib/model/autocomplete.dart @@ -758,12 +758,12 @@ sealed class ComposeAutocompleteResult extends AutocompleteResult {} /// An emoji chosen in an autocomplete interaction, via [EmojiAutocompleteView]. class EmojiAutocompleteResult extends ComposeAutocompleteResult { - EmojiAutocompleteResult(this.matchQuality, this.candidate); + EmojiAutocompleteResult(this.rank, this.candidate); - /// The quality of the emoji's match to the query. + /// A measure of the result's quality in the context of the query. /// /// Used internally by [EmojiAutocompleteView] for ranking the results. - final EmojiMatchQuality matchQuality; + final int rank; final EmojiCandidate candidate; } diff --git a/lib/model/emoji.dart b/lib/model/emoji.dart index 25f1f3c115..ff20a4e816 100644 --- a/lib/model/emoji.dart +++ b/lib/model/emoji.dart @@ -379,12 +379,13 @@ class EmojiAutocompleteView extends AutocompleteView r.rank, numBuckets: _numResultRanks); } EmojiAutocompleteResult? _testCandidate(EmojiAutocompleteQuery query, EmojiCandidate candidate) { final match = query.match(candidate); - return match == null ? null : EmojiAutocompleteResult(match, candidate); + if (match == null) return null; + return EmojiAutocompleteResult(_rankResult(match, candidate), candidate); } static const _numResultRanks = 9; @@ -411,11 +412,10 @@ class EmojiAutocompleteView extends AutocompleteView true, ReactionType.unicodeEmoji => false, }; - return switch (result.matchQuality) { + return switch (matchQuality) { EmojiMatchQuality.exact => throw Error(), // handled above EmojiMatchQuality.prefix => isPopular ? 1 : isCustomEmoji ? 3 : 5, EmojiMatchQuality.wordAligned => isPopular ? 2 : isCustomEmoji ? 4 : 6,