Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typeahead: Use common helper to calculate all should_remove_diacritics.
Pratik Chandaf9018bb954e6
diff --git a/web/src/people.ts b/web/src/people.tsindex 54ac404281c..caaa79b0e44 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -1183,19 +1183,12 @@ export function get_people_for_search_bar(query: string): User[] {return filter_all_persons(pred);}-export function should_remove_diacritics_for_query(query_lower_case: string): boolean {- // We only do diacritic-sensitive matching for queries that do not- // contain diacritics themselves. Spaces and other punctuation are- // irrelevant to this check.- return typeahead.remove_diacritics(query_lower_case) === query_lower_case;-}-export function maybe_remove_diacritics_from_name(user: User,should_remove_diacritics: boolean,): string {// Callers should compute should_remove_diacritics using- // should_remove_diacritics_for_query. It's fastest if the caller+ // contains_diacritics. It's fastest if the caller// computes that once outside the loop over all users.if (should_remove_diacritics) {// Reuse removed diacritics version of the `full_name` if@@ -1209,7 +1202,7 @@ export function maybe_remove_diacritics_from_name(export function build_termlet_matcher(termlet: string): (user: User) => boolean {// Note: termlets are required to be lower case.termlet = termlet.trim();- const should_remove_diacritics = should_remove_diacritics_for_query(termlet);+ const should_remove_diacritics = !typeahead.contains_diacritics(termlet);return function (user: User): boolean {const full_name = maybe_remove_diacritics_from_name(user, should_remove_diacritics);diff --git a/web/src/pill_typeahead.ts b/web/src/pill_typeahead.tsindex ebd5d196611..309b6eac977 100644--- a/web/src/pill_typeahead.ts+++ b/web/src/pill_typeahead.ts@@ -61,7 +61,7 @@ export function set_up_user(},matcher(query: string): (item: UserPillData) => boolean {query = typeahead.clean_query_lowercase(query, false);- const should_remove_diacritics = people.should_remove_diacritics_for_query(query);+ const should_remove_diacritics = !typeahead.contains_diacritics(query);return (item: UserPillData) => person_matcher(query, item, should_remove_diacritics);},sorter(matches: UserPillData[], query: string): UserPillData[] {@@ -161,7 +161,7 @@ export function set_up_user_group(},matcher(query: string): (item: UserGroupPillData) => boolean {query = typeahead.clean_query_lowercase(query, false);- const should_remove_diacritics = people.should_remove_diacritics_for_query(query);+ const should_remove_diacritics = !typeahead.contains_diacritics(query);return (item: UserGroupPillData) =>group_matcher(query, item, should_remove_diacritics);@@ -217,7 +217,7 @@ export function set_up_group_setting_typeahead(},matcher(query: string): (item: GroupSettingTypeaheadItem) => boolean {query = typeahead.clean_query_lowercase(query, false);- const should_remove_diacritics = people.should_remove_diacritics_for_query(query);+ const should_remove_diacritics = !typeahead.contains_diacritics(query);return (item: GroupSettingTypeaheadItem): boolean => {let matches = false;@@ -365,7 +365,7 @@ export function set_up_combined(},matcher(query: string): (item: TypeaheadItem) => boolean {query = typeahead.clean_query_lowercase(query, false);- const should_remove_diacritics = people.should_remove_diacritics_for_query(query);+ const should_remove_diacritics = !typeahead.contains_diacritics(query);return (item: TypeaheadItem): boolean => {if (include_streams(query) && item.type === "stream") {diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjsindex 2c39af21aaf..e2f30cd6948 100644--- a/web/tests/composebox_typeahead.test.cjs+++ b/web/tests/composebox_typeahead.test.cjs@@ -1507,8 +1507,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {function matcher(query, person) {query = typeahead.clean_query_lowercase(query, false);- const should_remove_diacritics =- people.should_remove_diacritics_for_query(query);+ const should_remove_diacritics = !typeahead.contains_diacritics(query);return typeahead_helper.query_matches_person(query,person,