Skip to content

Implemented locale-aware sorting for mention auto completion #1407

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

Closed
Closed
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
15 changes: 11 additions & 4 deletions lib/model/autocomplete.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:diacritic/diacritic.dart'; // Helps remove accents for better sorting
import 'package:flutter/widgets.dart'; // For Localizations.localeOf()

import '../api/model/events.dart';
import '../api/model/model.dart';
Expand Down Expand Up @@ -466,7 +467,7 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
/// particularly because [List.sort] makes no guarantees about the order
/// of items that compare equal.
int debugCompareUsers(User userA, User userB) {
return _comparator(store: store, narrow: narrow)(userA, userB);
return _comparator(store: store, narrow: narrow,)(userA, userB);
}

static int Function(User, User) _comparator({
Expand Down Expand Up @@ -599,7 +600,13 @@ class MentionAutocompleteView extends AutocompleteView<MentionAutocompleteQuery,
.normalizedNameForUser(userA);
final userBName = store.autocompleteViewManager.autocompleteDataCache
.normalizedNameForUser(userB);
return userAName.compareTo(userBName); // TODO(i18n): add locale-aware sorting

final normalizedA = removeDiacritics(userAName);
final normalizeB = removeDiacritics(userBName);

return normalizedA.compareTo(normalizeB);

// return userAName.compareTo(userBName); // TODO(i18n): add locale-aware sorting
}

void computeWildcardMentionResults({
Expand Down Expand Up @@ -744,7 +751,7 @@ class MentionAutocompleteQuery extends ComposeAutocompleteQuery {
required Narrow narrow,
}) {
return MentionAutocompleteView.init(
store: store, localizations: localizations, narrow: narrow, query: this);
store: store, localizations: localizations, narrow: narrow, query: this,);
}

bool testWildcardOption(WildcardMentionOption wildcardOption, {
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.2"
diacritic:
dependency: "direct main"
description:
name: diacritic
sha256: "12981945ec38931748836cd76f2b38773118d0baef3c68404bdfde9566147876"
url: "https://pub.dev"
source: hosted
version: "0.1.6"
drift:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies:
url_launcher_android: ">=6.1.0"
video_player: ^2.8.3
wakelock_plus: ^1.2.8
diacritic: ^0.1.6
zulip_plugin:
path: ./packages/zulip_plugin
# Keep list sorted when adding dependencies; it helps prevent merge conflicts.
Expand Down