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: Display the typeahead before the user starts typing.

Sumanth V Raoad8f27e20ccd
diff --git a/static/js/realm_playground.js b/static/js/realm_playground.js
index 3633174c50f..bc87febd2ff 100644
--- a/static/js/realm_playground.js
+++ b/static/js/realm_playground.js
@@ -49,11 +49,13 @@ export function get_pygments_typeahead_list(query) {
// 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},
- );
+ if (clean_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(", ") + ")";
diff --git a/static/js/settings_playgrounds.js b/static/js/settings_playgrounds.js
index 13953188781..4a1ef9313e1 100644
--- a/static/js/settings_playgrounds.js
+++ b/static/js/settings_playgrounds.js
@@ -151,9 +151,10 @@ function build_page() {
});
});
+ const search_pygments_box = $("#playground_pygments_language");
let lookup_table = new Map();
- $("#playground_pygments_language").typeahead({
+ search_pygments_box.typeahead({
source(query) {
const suggestions = realm_playground.get_pygments_typeahead_list(query);
lookup_table = suggestions.lookup_table;
@@ -161,6 +162,7 @@ function build_page() {
},
items: 5,
fixed: true,
+ helpOnEmptyStrings: true,
highlighter(item) {
return lookup_table[item];
},
@@ -169,4 +171,10 @@ function build_page() {
return item.toLowerCase().startsWith(q);
},
});
+
+ search_pygments_box.on("click", (e) => {
+ search_pygments_box.typeahead("lookup").trigger("select");
+ e.preventDefault();
+ e.stopPropagation();
+ });
}