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 an option to select "Custom language" in typeahead.

Sumanth V Rao9c4ed43d6b17
diff --git a/static/js/realm_playground.js b/static/js/realm_playground.js
index b5fff309ea0..3633174c50f 100644
--- a/static/js/realm_playground.js
+++ b/static/js/realm_playground.js
@@ -1,3 +1,6 @@
+import * as typeahead from "../shared/js/typeahead";
+
+import {$t} from "./i18n";
import * as typeahead_helper from "./typeahead_helper";
const map_language_to_playground_info = new Map();
@@ -39,10 +42,19 @@ export function sort_pygments_pretty_names_by_priority(generated_pygments_data)
}
}
-export function get_pygments_typeahead_list() {
+export function get_pygments_typeahead_list(query) {
const lookup_table = new Map();
const pygments_pretty_name_list = [];
+ // Adds a typeahead that allows selecting a custom language, by adding a
+ // "Custom language" label in the first position of the typeahead list.
+ const clean_query = typeahead.clean_query_lowercase(query);
+ pygments_pretty_name_list.push(clean_query);
+ lookup_table[clean_query] = $t(
+ {defaultMessage: "Custom language: {query}"},
+ {query: clean_query},
+ );
+
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);
diff --git a/static/js/settings_playgrounds.js b/static/js/settings_playgrounds.js
index b6576d7eafb..13953188781 100644
--- a/static/js/settings_playgrounds.js
+++ b/static/js/settings_playgrounds.js
@@ -154,8 +154,8 @@ function build_page() {
let lookup_table = new Map();
$("#playground_pygments_language").typeahead({
- source() {
- const suggestions = realm_playground.get_pygments_typeahead_list();
+ source(query) {
+ const suggestions = realm_playground.get_pygments_typeahead_list(query);
lookup_table = suggestions.lookup_table;
return suggestions.pygments_pretty_name_list;
},