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.

typeahead: Normalize spaces for sorting emojis, just like for filtering.

Greg Pricece2014bfef18
diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.js
index 04c185916b9..2d02ad73765 100644
--- a/frontend_tests/node_tests/typeahead.js
+++ b/frontend_tests/node_tests/typeahead.js
@@ -189,3 +189,19 @@ run_test("sort_emojis: SM", () => {
"big_smile",
]);
});
+
+run_test("sort_emojis: prefix before midphrase, with underscore (traffic_li)", () => {
+ const emoji_list = [{emoji_name: "horizontal_traffic_light"}, {emoji_name: "traffic_light"}];
+ assert.deepEqual(sort_emojis(emoji_list, "traffic_li"), [
+ "traffic_light",
+ "horizontal_traffic_light",
+ ]);
+});
+
+run_test("sort_emojis: prefix before midphrase, with space (traffic li)", () => {
+ const emoji_list = [{emoji_name: "horizontal_traffic_light"}, {emoji_name: "traffic_light"}];
+ assert.deepEqual(sort_emojis(emoji_list, "traffic li"), [
+ "traffic_light",
+ "horizontal_traffic_light",
+ ]);
+});
diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js
index f3dfe12d76a..6315eedfe60 100644
--- a/static/shared/js/typeahead.js
+++ b/static/shared/js/typeahead.js
@@ -82,7 +82,7 @@ export function clean_query_lowercase(query) {
}
export function get_emoji_matcher(query) {
- // replaces spaces with underscores for emoji matching
+ // replace spaces with underscores for emoji matching
query = query.replace(/ /g, "_");
query = clean_query_lowercase(query);
@@ -131,6 +131,8 @@ export function triage(query, objs, get_item = (x) => x) {
}
export function sort_emojis(objs, query) {
+ // replace spaces with underscores for emoji matching
+ query = query.replace(/ /g, "_");
query = query.toLowerCase();
function decent_match(name) {