Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
realm_playground: Cut dependency on `typeahead_helper.js`.
Lalit8c12494c16e6
diff --git a/web/src/realm_playground.js b/web/src/realm_playground.jsindex fc5fa69e139..b1068567fdf 100644--- a/web/src/realm_playground.js+++ b/web/src/realm_playground.js@@ -2,7 +2,6 @@ import generated_pygments_data from "../generated/pygments_data.json";import * as typeahead from "../shared/src/typeahead";import {$t} from "./i18n";-import * as typeahead_helper from "./typeahead_helper";const map_language_to_playground_info = new Map();const map_pygments_pretty_name_to_aliases = new Map();@@ -28,9 +27,9 @@ export function get_playground_info_for_languages(lang) {return map_language_to_playground_info.get(lang);}-export function sort_pygments_pretty_names_by_priority(generated_pygments_data) {+function sort_pygments_pretty_names_by_priority(generated_pygments_data, comparator_func) {const priority_sorted_pygments_data = Object.keys(generated_pygments_data.langs).sort(- typeahead_helper.compare_language,+ comparator_func,);for (const alias of priority_sorted_pygments_data) {const pretty_name = generated_pygments_data.langs[alias].pretty_name;@@ -84,7 +83,7 @@ export function get_pygments_typeahead_list_for_settings(query) {return language_labels;}-export function initialize(playground_data, generated_pygments_data) {+export function initialize({playground_data, generated_pygments_data, pygments_comparator_func}) {update_playgrounds(playground_data);- sort_pygments_pretty_names_by_priority(generated_pygments_data);+ sort_pygments_pretty_names_by_priority(generated_pygments_data, pygments_comparator_func);}diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex a11f3b4f444..e8154442cd9 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -108,6 +108,7 @@ import * as top_left_corner from "./top_left_corner";import * as topic_list from "./topic_list";import * as topic_zoom from "./topic_zoom";import * as tutorial from "./tutorial";+import * as typeahead_helper from "./typeahead_helper";import * as typing from "./typing";import * as unread from "./unread";import * as unread_ops from "./unread_ops";@@ -712,7 +713,11 @@ export function initialize_everything() {message_scroll.initialize();markdown.initialize(markdown_config.get_helpers());linkifiers.initialize(page_params.realm_linkifiers);- realm_playground.initialize(page_params.realm_playgrounds, generated_pygments_data);+ realm_playground.initialize({+ playground_data: page_params.realm_playgrounds,+ generated_pygments_data,+ pygments_comparator_func: typeahead_helper.compare_language,+ });compose.initialize();// Typeahead must be initialized after compose.initialize()composebox_typeahead.initialize({diff --git a/web/tests/realm_playground.test.js b/web/tests/realm_playground.test.jsindex a1d8bd8a4b4..9ef6229bb96 100644--- a/web/tests/realm_playground.test.js+++ b/web/tests/realm_playground.test.js@@ -9,6 +9,7 @@ const pygments_data = zrequire("../generated/pygments_data.json");const {$t} = zrequire("i18n");const realm_playground = zrequire("realm_playground");+const typeahead_helper = zrequire("typeahead_helper");run_test("get_pygments_typeahead_list_for_composebox", () => {// When no Code Playground is configured, the list of candidates should@@ -27,7 +28,11 @@ run_test("get_pygments_typeahead_list_for_composebox", () => {url_prefix: "https://example.com/?q=",},];- realm_playground.initialize(playground_data, pygments_data);+ realm_playground.initialize({+ playground_data,+ generated_pygments_data: pygments_data,+ pygments_comparator_func: typeahead_helper.compare_language,+ });// Verify that Code Playground's pygments_language shows up in the result.// As well as all of pygments_data. Order doesn't matter and the result@@ -63,7 +68,11 @@ run_test("get_pygments_typeahead_list_for_settings", () => {url_prefix: "https://example.com/?q=",},];- realm_playground.initialize(playground_data, pygments_data);+ realm_playground.initialize({+ playground_data,+ generated_pygments_data: pygments_data,+ pygments_comparator_func: typeahead_helper.compare_language,+ });let candidates = realm_playground.get_pygments_typeahead_list_for_settings("");let iterator = candidates.entries();