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.

playgrounds: Add pygment aliases into a parenthetical in the typeahead.

Sumanth V Raoad76df25ac31
diff --git a/static/js/realm_playground.js b/static/js/realm_playground.js
index ba585a08ee4..b5fff309ea0 100644
--- a/static/js/realm_playground.js
+++ b/static/js/realm_playground.js
@@ -1,7 +1,7 @@
import * as typeahead_helper from "./typeahead_helper";
const map_language_to_playground_info = new Map();
-const pygments_pretty_name_list = new Set();
+const map_pygments_pretty_name_to_aliases = new Map();
export function update_playgrounds(playgrounds_data) {
map_language_to_playground_info.clear();
@@ -28,18 +28,30 @@ 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,
);
- for (const data of priority_sorted_pygments_data) {
- const pretty_name = generated_pygments_data.langs[data].pretty_name;
- // JS maintains the order of insertion in a set so we don't need to worry about
- // the priority changing.
- if (!pygments_pretty_name_list.has(pretty_name)) {
- pygments_pretty_name_list.add(pretty_name);
+ for (const alias of priority_sorted_pygments_data) {
+ const pretty_name = generated_pygments_data.langs[alias].pretty_name;
+ // JS Map remembers the original order of insertion of keys.
+ if (map_pygments_pretty_name_to_aliases.has(pretty_name)) {
+ map_pygments_pretty_name_to_aliases.get(pretty_name).push(alias);
+ } else {
+ map_pygments_pretty_name_to_aliases.set(pretty_name, [alias]);
}
}
}
-export function get_pygments_pretty_names_list() {
- return Array.from(pygments_pretty_name_list);
+export function get_pygments_typeahead_list() {
+ const lookup_table = new Map();
+ const pygments_pretty_name_list = [];
+
+ for (const [key, values] of map_pygments_pretty_name_to_aliases) {
+ lookup_table[key] = key + " (" + Array.from(values).join(", ") + ")";
+ pygments_pretty_name_list.push(key);
+ }
+
+ return {
+ pygments_pretty_name_list,
+ lookup_table,
+ };
}
export function initialize(playground_data, generated_pygments_data) {
diff --git a/static/js/settings_playgrounds.js b/static/js/settings_playgrounds.js
index e1ccf90a019..b6576d7eafb 100644
--- a/static/js/settings_playgrounds.js
+++ b/static/js/settings_playgrounds.js
@@ -7,7 +7,6 @@ import {$t_html} from "./i18n";
import * as ListWidget from "./list_widget";
import {page_params} from "./page_params";
import * as realm_playground from "./realm_playground";
-import * as typeahead_helper from "./typeahead_helper";
import * as ui from "./ui";
import * as ui_report from "./ui_report";
@@ -152,14 +151,18 @@ function build_page() {
});
});
+ let lookup_table = new Map();
+
$("#playground_pygments_language").typeahead({
source() {
- return realm_playground.get_pygments_pretty_names_list();
+ const suggestions = realm_playground.get_pygments_typeahead_list();
+ lookup_table = suggestions.lookup_table;
+ return suggestions.pygments_pretty_name_list;
},
items: 5,
fixed: true,
highlighter(item) {
- return typeahead_helper.render_typeahead_item({primary: item});
+ return lookup_table[item];
},
matcher(item) {
const q = this.query.trim().toLowerCase();