Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: emoji autocomplete, match insensitively to diacritics #1459

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/model/emoji.dart
Original file line number Diff line number Diff line change
@@ -1,6 +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';
import '../api/model/model.dart';
Expand Down Expand Up @@ -462,7 +462,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
Expand Down Expand Up @@ -508,17 +508,16 @@ 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;
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
crypto: ^3.0.3
device_info_plus: ^11.2.0
drift: ^2.23.0
diacritic: ^0.1.6
file_picker: ^9.0.2
firebase_core: ^3.3.0
firebase_messaging: ^15.0.1
Expand Down