Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typeahead: Rename compare_by_popularity() for clarity.

Trident Pancakecb6c1c4f05fb
diff --git a/web/src/realm_playground.js b/web/src/realm_playground.js
index b13eebd1360..d42f34b7d71 100644
--- a/web/src/realm_playground.js
+++ b/web/src/realm_playground.js
@@ -29,7 +29,7 @@ export function get_playground_info_for_languages(lang) {
export function sort_pygments_pretty_names_by_priority(generated_pygments_data) {
const priority_sorted_pygments_data = Object.keys(generated_pygments_data.langs).sort(
- typeahead_helper.compare_by_popularity,
+ typeahead_helper.compare_language,
);
for (const alias of priority_sorted_pygments_data) {
const pretty_name = generated_pygments_data.langs[alias].pretty_name;
diff --git a/web/src/typeahead_helper.js b/web/src/typeahead_helper.js
index 6ab0bef3e31..4336a5b35a9 100644
--- a/web/src/typeahead_helper.js
+++ b/web/src/typeahead_helper.js
@@ -259,7 +259,9 @@ export function sort_people_for_relevance(objs, current_stream_name, current_top
return objs;
}
-export function compare_by_popularity(lang_a, lang_b) {
+// This function compares two languages first by their popularity, then if
+// there is a tie on popularity, then compare alphabetically to break the tie.
+export function compare_language(lang_a, lang_b) {
const diff = pygments_data.langs[lang_b].priority - pygments_data.langs[lang_a].priority;
if (diff !== 0) {
return diff;
@@ -289,7 +291,7 @@ export function sort_languages(matches, query) {
const results = typeahead.triage(query, matches, (x) => x);
// Languages that start with the query
- results.matches = results.matches.sort(compare_by_popularity);
+ results.matches = results.matches.sort(compare_language);
// Push exact matches to top.
const match_index = results.matches.indexOf(query);
@@ -299,7 +301,7 @@ export function sort_languages(matches, query) {
}
// Languages that have the query somewhere in their name
- results.rest = results.rest.sort(compare_by_popularity);
+ results.rest = results.rest.sort(compare_language);
return retain_unique_language_aliases(results.matches.concat(results.rest));
}