From ff6d73db64692d9dd2a2d91f4fb9ed1ae5518a0e Mon Sep 17 00:00:00 2001 From: ashutoshkhadse Date: Sun, 4 May 2025 20:33:43 +0530 Subject: [PATCH] fix: emoji diacritic --- lib/model/emoji.dart | 17 +++++++++-------- pubspec.yaml | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/model/emoji.dart b/lib/model/emoji.dart index 670c574c12..74f73998fd 100644 --- a/lib/model/emoji.dart +++ b/lib/model/emoji.dart @@ -1,5 +1,6 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; +import 'package:diacritic/diacritic.dart'; import '../api/model/events.dart'; import '../api/model/initial_snapshot.dart'; @@ -459,7 +460,7 @@ class EmojiAutocompleteQuery extends ComposeAutocompleteQuery { static const _separator = '_'; static String _adjustQuery(String raw) { - return raw.toLowerCase().replaceAll(' ', '_'); // TODO(#1067) remove diacritics too + return removeDiacritics(raw.toLowerCase()).replaceAll(' ', '_'); } @override @@ -505,17 +506,17 @@ class EmojiAutocompleteQuery extends ComposeAutocompleteQuery { // for the finer distinctions. // See also commentary in [_rankResult]. - // TODO(#1067) this assumes emojiName is already lower-case (and no diacritics) - if (emojiName == _adjusted) return EmojiMatchQuality.exact; - if (emojiName.startsWith(_adjusted)) return EmojiMatchQuality.prefix; - if (emojiName.contains(_sepAdjusted)) return EmojiMatchQuality.wordAligned; + final normalizedEmojiName = removeDiacritics(emojiName.toLowerCase()); + + if (normalizedEmojiName == _adjusted) return EmojiMatchQuality.exact; + if (normalizedEmojiName.startsWith(_adjusted)) return EmojiMatchQuality.prefix; + if (normalizedEmojiName.contains(_sepAdjusted)) return EmojiMatchQuality.wordAligned; if (!_adjusted.contains(_separator)) { // If the query is a single token (doesn't contain a separator), // allow a match anywhere in the string, too. - if (emojiName.contains(_adjusted)) return EmojiMatchQuality.other; - } else { - // Otherwise, require at least a word-aligned match. + if(normalizedEmojiName.contains(_adjusted)) return EmojiMatchQuality.other; } + return null; } diff --git a/pubspec.yaml b/pubspec.yaml index a1c9f6dd2d..6123a7f42c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: csslib: ^1.0.2 device_info_plus: ^11.2.0 drift: ^2.23.0 + diacritic: ^0.1.6 file_picker: ^10.1.2 firebase_core: ^3.3.0 firebase_messaging: ^15.0.1