people: Improve mentioning users with diacritics in their name.

This makes it possible to mention a user with a name like Gaël that
contains diacritics by typing e.g. "Gael", significantly reducing the
need to use a special keyboard to mention other users.

Fixes #11183.
This commit is contained in:
ss62171
2019-01-23 02:33:50 +05:30
committed by Tim Abbott
parent 805ec5fbdb
commit b7a0a45f01
3 changed files with 22 additions and 4 deletions

View File

@@ -197,12 +197,19 @@ var twin2 = {
email: 'twin2@zulip.com',
};
var gael = {
full_name: 'Gaël Twin',
user_id: 107,
email: 'twin3@zulip.com',
};
global.people.add_in_realm(hamlet);
global.people.add_in_realm(othello);
global.people.add_in_realm(cordelia);
global.people.add_in_realm(lear);
global.people.add_in_realm(twin1);
global.people.add_in_realm(twin2);
global.people.add_in_realm(gael);
global.people.add(deactivated_user);
var hamletcharacters = {
@@ -529,7 +536,7 @@ run_test('initialize', () => {
// This should match the users added at the beginning of this test file.
var actual_value = options.source();
var expected_value = [hamlet, othello, cordelia, lear,
twin1, twin2, hamletcharacters, backend];
twin1, twin2, gael, hamletcharacters, backend];
assert.deepEqual(actual_value, expected_value);
// Even though the items passed to .highlighter() are the full
@@ -560,6 +567,15 @@ run_test('initialize', () => {
assert.equal(options.matcher(othello), false);
assert.equal(options.matcher(cordelia), false);
options.query = 'gael';
assert.equal(options.matcher(gael), true);
options.query = 'Gaël';
assert.equal(options.matcher(gael), true);
options.query = 'gaël';
assert.equal(options.matcher(gael), true);
// Don't make suggestions if the last name only has whitespaces
// (we're between typing names).
options.query = 'othello@zulip.com, ';

View File

@@ -50,6 +50,8 @@ function query_matches_language(query, lang) {
}
function query_matches_string(query, source_str, split_char) {
source_str = people.remove_diacritics(source_str);
query = people.remove_diacritics(query);
// When `abc ` with a space at the end is typed in a
// contenteditable widget such as the composebox PM section, the
// space at the end was a `no break-space (U+00A0)` instead of

View File

@@ -739,7 +739,7 @@ exports.incr_recipient_count = function (user_id) {
// Diacritic removal from:
// https://stackoverflow.com/questions/18236208/perform-a-find-match-with-javascript-ignoring-special-language-characters-acce
function remove_diacritics(s) {
exports.remove_diacritics = function (s) {
if (/^[a-z]+$/.test(s)) {
return s;
}
@@ -751,7 +751,7 @@ function remove_diacritics(s) {
.replace(/[úùüû]/g, "u")
.replace(/[ç]/g, "c")
.replace(/[ñ]/g, "n");
}
};
exports.person_matches_query = function (user, query) {
var email = user.email.toLowerCase();
@@ -770,7 +770,7 @@ exports.person_matches_query = function (user, query) {
return _.any(names, function (name) {
if (is_ascii) {
// Only ignore diacritics if the query is plain ascii
name = remove_diacritics(name);
name = exports.remove_diacritics(name);
}
if (name.indexOf(termlet) === 0) {
return true;