mirror of https://github.com/zulip/zulip.git
realm_playground: Cut dependency on `typeahead_helper.js`.
This commit is contained in:
parent
af648833f2
commit
8c12494c16
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue